admin管理员组文章数量:1331687
I need to upload files along with other data from a Nativescript app. Here is what I am doing:
const data = new FormData();
data.append('name', 'Some Name');
data.append('profile_picture', profilePic);
Here profile pic is a nativescript File object. It does not seem to work as expected. It is sent to server as "[object object]".
How to do upload the file in form data?
I need to upload files along with other data from a Nativescript app. Here is what I am doing:
const data = new FormData();
data.append('name', 'Some Name');
data.append('profile_picture', profilePic);
Here profile pic is a nativescript File object. It does not seem to work as expected. It is sent to server as "[object object]".
How to do upload the file in form data?
Share Improve this question edited Sep 5, 2016 at 16:50 RPichioli 3,3453 gold badges27 silver badges31 bronze badges asked Sep 5, 2016 at 16:34 Prabhakar BhatPrabhakar Bhat 1,4632 gold badges12 silver badges16 bronze badges 4- Have your tried this? nativescript.github.io/nativescript-background-http – inf3rno Commented Sep 5, 2016 at 18:07
- 4 Yes, it only allows to upload files directly as octet stream. Not as part of formdata. – Prabhakar Bhat Commented Sep 5, 2016 at 18:31
- 2 If you want to send it as a form data, you could encode your picture in base64 – Kansen Commented Sep 6, 2016 at 15:05
- 1 That's fine for picture, but elsewhere I need to send video as well. base64 may not be the best way. – Prabhakar Bhat Commented Sep 8, 2016 at 6:18
2 Answers
Reset to default 4Since January https://github./NativeScript/nativescript-background-http supports multipart uploads, too.
Example:
var request = {
url: url,
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": name
},
description: description
};
var params = [{name: "test", value: "value"}, {name:"fileToUpload", filename: file, mimeType: 'image/jpeg'}];
task = session.multipartUpload(params, request);
Binary support should be ing in NativeScript v6.3
. See this issue. You should then no longer need to use nativescript-background-http
. You can see my full write-up here.
本文标签: javascriptHow to upload file using multipart form data in nativescriptStack Overflow
版权声明:本文标题:javascript - How to upload file using multipart form data in nativescript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742216249a2434619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论