I'm trying to upload an Base64 encoded image to google drive using Jquery AJAX POST request. IT uploaded the data on Google drive but it doesn't show the image on Google Drive viewer / after downloading the file.
The request call gets success message with JSON response.
Following is the snippet of the code: [imageData is Base64 encoded string]
$.ajax({
type: 'POST',
url: 'https://www.googleapis.com/upload/drive/v2/files?uploadType=media',
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'image/jpeg',
'Content-Length': imageData.length, // imageData is Base64 encoded string
},
data: imageData // imageData is Base64 encoded string
}).done(function (result, textStatus, jqXHR) {
console.log('success : ' + textStatus);
console.log(JSON.stringify(result));
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log('fail : ' + textStatus + ' desc : ' + SON.stringify(jqXHR));
});
Thanks in advance.
- Vishrut