Upload new version in file - Getting "Unsupported Media Type"
Hi, I have tried BOX Upload a file version post API. But am getting an 415 -Unsupported media type or 400 - API upload did not have a file part error.
Here what i have tried is in POST API am trying to upload new version of file using React JS (axios post)
METHOD : post
URL : https://upload.box.com/api/2.0/files//content
HEADERS: Authorization : 'Bearer ', content-type : 'multipart/form-data'
BODY: ‘attributes’:{‘name’:’filename.json’}, ‘file’:
-
Hi ,
Could you try changing the content-type to "application/json", since you're uploading a JSON file, and see if that solves the problem please?
If that doesn't work can you supply your code please? The 400 error is telling me that there's an issue with the request coming through.
Thanks,
Jon
-
Hi ,
Thanks. I have tried using the content-type as "application/json" but 415 error persists. PFB the code i have tried,
let filePath = "../../folder1/fileName.json"; var form = new FormData(); form.append("attributes", "{name:fileName.json}"); form.append("file", filePath); return axios({ method: 'POST', url: `https://upload.box.com/api/2.0/files/${FILE_ID}/content`, data: form, headers: { 'Authorization': 'Bearer ' + access_token, 'content-type': 'multipart/form-data; boundary=---- WebKitFormBoundary7MA4YWxkTrZu0gW', // Response : 400 - API upload didnot have a file part // 'content-type': 'application/json', -> Response : 415 - unsupported media type // 'content-type': 'application/x-www-form-urlencoded', -> 415 - unsupported media type }, }).then(function (response) { console.log("response", response) return response.data; }).catch((error) => { console.log('error', error); });
Please sign in to leave a comment.
Comments
3 comments