Both headers are valid in any message or body part. They are valid for the content heading or message heading where they occur and for its content. The Content-Location and Content-Base headers apply to headers and body parts where they occur and do not have meaning in multipart headings. The following example shows how these headers are used:. It is finding wider use in machine-to-machine communication. These headers do not define security protocols, but exist to carry the protected documents.
The control information is carried in the second of the two required body parts. You'll see how to allow the picture selection from the device gallery using the UIIMagePickerController and how to define the callback delegate called as soon as the image has been selected.
You'll learn then how to send the image through a post request with more post parameters. Let's start by opening Swift and by creating a new iOS single view app. In order to allow the http protocol in swift 2, you'll need to edit the info. Search for the info.
Let's define now the Layout of the project. Open the main. Now let's add inside the ViewController two buttons and an ImageView , like the image below:. The Choose an image button will open the iOS Image Picker , the UIImageView will let us preview the selected image, while the Upload button will upload it on the server using a mutipart post request.
Let's now link , using the assistant editor , the inserted views to the variables. Click on the assistant editor , and drag and drop the elements inside the ViewController class by holding the CTRL button. Start from the Choose an image button and link it to an IBAction event.
In this example I've called it selectPicture. Link now the Upload button to another IBAction event. Let's now implement the selectPicture function. This will define the callback class, called as soon as an image has been selected. PhotoLibrary self. UIImage self. Now the button choose an image will call the UIImagePickerController istance, and as soon as an image is selected, the imagePickerController callback is called. This function will display the selected image in the preview , and dismiss the UIImagePickerController view.
It's now time to upload the image on the server. For this example I've prepared a simple php script. This script will just read the file field of the request and put back the file image name. In this example we'll send the file and an additional post parameter, called test in this case. Here you'll find the project for this example: download. About Contact. KaleidosBlog TechnoVision. How to upload images using swift 2: send multipart post request In this new iOS 9 tutorial you'll see how to upload an image to a server with a multipart post request using swift 2.
PathVariable; import org. RequestMapping; import org. RequestMethod; import org. RequestParam; import org. RestController; import org. MultipartFile; import com. RecordNotFoundException; import com. Employee; import com. Multipart upload request demo For demo purpose, I have created a JSP page with only single field of type file. Sourcecode Download. Was this post helpful? Let us know if you liked the post. HowToDoInJava A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.
Part name: "b", value: "2" , MultipartForm. Part name: "c", data: imageData, filename: "3. Amirhossein72 Amirhossein72 5 5 silver badges 7 7 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast what if you could invest in your favorite developer?
Who owns this outage? Building intelligent escalation chains for modern SRE. Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer. Linked
0コメント