I can upload the pdf file, but it will upload as blank/empty file. I don't know what am i missing from here.
Backend i receive the file, i also tried without converting to Base64
and still the same thing.
using (var sr = new StreamReader(file.OpenReadStream(), System.Text.Encoding.UTF8))
{
_fContent = await sr.ReadToEndAsync();
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(_fContent);
_fContent = System.Convert.ToBase64String(plainTextBytes);
}
Frontend i create the request.
endpoint = 'https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&fields=id';
method = 'POST';
_metadata = {
'name': fileName,
'mimeType': 'application/pdf',
'parents': [zzzz]
};
//blob is the data we receive in backend from _fContent variable
var file = new Blob([blob], { type: 'application/pdf' });
var accessToken = gapi.auth.getToken().access_token;
var form = new FormData();
form.append('metadata', new Blob([JSON.stringify(_metadata)], { type: 'application/json' }));
form.append('file', file);
var xhr = new XMLHttpRequest();
xhr.open(method, endpoint);
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.responseType = 'json';
xhr.onload = () => {
GapiUploadCallback(xhr.response, responseReturn);
};
xhr.send(form);
This is what i receive in google drive API, an empty/blank PDF file. Note: File size is 1 MB (1,424,457 bytes)