How to upload file using multipart/form-data in nativescript?



I’m going to upload images and text using multiform-data.
but I failed.

post_part_deviation(project_id, part_id, p_deviation, s_solution){
let body: any = {
project_id: project_id,
part_id: part_id,
photo_deviation:p_deviation,/////image url
photo_solution:s_solution/////////////image url
let str = [];
for(let p in body) {
str.push(encodeURIComponent§ + “=” + encodeURIComponent(body[p]));
body = str.join("&");
let headers = new Headers();
headers.append(“Content-Type”, “multipart/form-data”);
let options = new RequestOptions({ headers: headers });
return“http://url/api/project_part_deviations”, body, options)
.then((data) => {
handleErrors(error: Response) {
return Observable.throw(error);

Please check my code.


hi, could you give us some information about the error that occurs? Also you can format your code so it’s easier to read by using the </> button.


Nativescript support file upload functionality using multipart/form-data ?


did you do a quick Google on this?


A couple months ago I added Multipart-form upload capability to plugin.

To my knowledge this is the ONLY way currently to do multipart-form uploads.

Nathanael A.


?so, this “Content-Type”: “application/octet-stream” is the same multiPart formdata? i dont need change anything in the server to use this content type?


Actually you can omit “Content-Type”: “application/octet-stream” if it’s not needed for your backend.
Here is an example of file upload to QuickBlox (which uses AWS S3 under the hood with “multipart/form-data” supported)

I just pass

var request = {
            url: uploadUrl,
            method: "POST"

and use

var task = session.multipartUpload(uploadParams, request);


I also needed this. so i created a plugin