Sign In Register

How can we help you today?

Start a new topic
Answered

Uploading binary content using Javascript SDK

I've had a look up and down the forums for an answer but can't find anything that will expedite this problem.


So i know the workflow is the following:


Get uploaded URL request.

Once that is done. Post to the URL with some data form.


I have tried doing this but get an error stating ' cannot upload file'.


Looks like i can't post any type of data to this URL, as i get the same error. Test Harness works just find and when i use a HTTP Request tester online ,i get the same errors as well. 


My question really is:


What are the required headers and parameters for this post?

Is it possible to take a look at the test harness upload feature form source so i can understand the make-up of the request and what is required?



 

var blob = MSApp.createBlobFromRandomAccessStream("image/jpeg", stream);

 var data = new FormData();
data.append("snapshot", blob, filename);

  return WinJS.xhr({
       type: "POST",
       url: gsUploadURL,
      data: data
    })
     .then(function complete(result) {

  


Thanks.


Best Answer

Hi Yaser,


I've put together a very simple project to illustrate how you can go about binary uploads with the Javascript SDK, this example uses html forms, but by inspecting the headers you should be able to achieve the same in xhr / ajax. You'll need to fill in your apiKey and apiSecret. It might be also useful to open the developer console while doing this to watch the debug console throughout the process.


I hope this helps, kind regards,

 - Steve

zip

I will also add that i created an event, that uploads a Uint8Array from an image and stores it in a noSQL database. When i open the database it feels really slow. So this being a test, it didn't go so well i reckon. I also experienced some disconnections due to this. I won't be doing this but felt it was worth mentioning. 

Any ideas guys?

Answer

Hi Yaser,


I've put together a very simple project to illustrate how you can go about binary uploads with the Javascript SDK, this example uses html forms, but by inspecting the headers you should be able to achieve the same in xhr / ajax. You'll need to fill in your apiKey and apiSecret. It might be also useful to open the developer console while doing this to watch the debug console throughout the process.


I hope this helps, kind regards,

 - Steve

zip
Login to post a comment