Start a new topic

HTML5 upload error 400 ()

Hello 

I just wanted to let you know about this:

When I upload a file by HTML5 API I got an error using your Upload sample from here:

Failed to load resource: the server responded with a status of 400 ()

console error message:

code: 400

debug: undefined

kinveyRequestId: undefined

message: "An error occurred."

name: "KinveyError"

stack: "o@https://da189i1jfloii.cloudfront.net/js/kinvey-html5-sdk-3.11.2.min.js:8:20525…"


The file still will be uploaded!


I found out that your sample is not complete:


  1. var metadata ={
  2. _id: '<file-id>',
  3. filename: '<filename>',
  4. mimeType: '<mime-type>'
  5. };


After I added "size: <filesize> to the metadata it worked without any errors. Maybe you want to adjust your sample.


Regards


Hi Tayger,


I implemented your scenario on API console and didn't face any issues. Did you include "Content-Type" and "X-Kinvey-Content-Type" headers while implementing your use-case? Can you also implement this scenario on API console and share the results? Please share the screenshots of both the requests and outputs.


Thanks,

Pranav

Hello Pranav


Thank you for your answer. Umm, no, I didn't include 'Content-Type and 'X-Kinvey-Content-Type'. I can't find anything about those types from where I got the sample codes: here

If you let me know where I got information about those, i.e. how to implement them I can try it. Here is my related code doing the upload. It's a bigger project and not that easy to let it run over the console since I upload files that I have previously stored in an indexedDB. Furthermore I guess that the console does not reveal all errors that appears connecting from client.


// Get file from indexedDB to upload
dbReadFile(media.id)
.
then(function(dbFile) {
// Conversion required: ArrayBuffer is deprecated in XMLHttpRequest.send(). Use ArrayBufferView instead.
var fileContent = new DataView(dbFile.file);
var metaData = {
'_id': media.id,
'gameid': 'GS',
'filename': 'gs-' + media.id + '.' + media.extension,
'mimeType': media.type,
'size': media.size, // otherwise error (400)
'type': media.type.substring(0, media.type.indexOf("/")).toLowerCase()
// public: true
};

// Upload file
var promise = Kinvey.Files.upload(fileContent, metaData)
.
then(function(file) {
delete media.state;
})
.
catch(function(error) {
console.log (error);
});
});

I'm fine with that, it works. :o) 


Regards

Tayger


Login or Signup to post a comment