POST /upload/drive/v2/files?uploadType=media HTTP/1.1 Host: www.googleapis.com Content-Type: image/jpeg Content-Length: {number_of_bytes_in_JPEG_file} Authorization: {your_auth_token} {JPEG data}which is nothing but a simple file upload using google drive API. I am trying to upload an image to google drive. I use this as the reference
var reader = new FileReader(); var fileContent = this.$.fileInput.getFiles()[0]; reader.readAsBinaryString(fileContent); reader.onload = function(e) { var contentType = fileContent.type; var contentSize = fileContent.size; var authCode = access_token; var requestBody = reader.result; var driveAjax = new enyo.Ajax({ url: 'https://www.googleapis.com/upload/drive/v2/files?uploadType=media', method: 'POST', headers: { 'Content-Type' : contentType, 'Content-Length' : contentSize, 'Authorization' : authCode }, postBody: requestBody }); driveAjax.response(this, "uploadSuccess"); driveAjax.error(this, "processError"); driveAjax.go(); }I have checked all the data and that is correct. But I get neither success nor any error. Can anyone tell where am I going wrong.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I believe the reason you're seeing what you are is due to variable scoping. You see, you're calling
this
from inside a function that's not scoped to the samethis
as your code outside of that function. To fix that I'd recommend you do the following: What that does is ensure that you have the proper scope to the properthis
, but also provides your function with the fileContent variable.