Hello All,
I want to upload an images from BinaryString using Javascript(Not Node).
My code can uploaded text files(TXT, HTML etc).
Images(JPG, PNG, PDF etc) also can uploaded but they are broken.
I want to upload the image file without any problems.
How can I solve this problem?
The following is my code.
function Upload_Box(Binary){
var token = "TOKEN";
var blob = new Blob([Binary], {type: 'image/jpg'});
//var file = new File([blob], 'test.jpg');
var form = new FormData();
form.append('Authorization', 'Bearer ' + token);
//form.append('file', file);
form.append('file', blob);
form.append('attributes', '{"name":"test.jpg", "parent":{"id":"0"}}');
$.ajax({
url:"https://upload.box.com/api/2.0/files/content",
type:"POST",
contentType: false,
processData: false,
mimeType: "multipart/form-data",
headers: {
Authorization: "Bearer " + token,
},
data: form,
}).done( function (data){
console.log(data);
});
}
Thanks,
Daeseung