I am developing a visualforce page. I'm trying to upload pdf-file from remote server in contentversion , here is part of my code:
let response = await fetch('http://www.africau.edu/images/default/sample.pdf');
let blob = await response.blob();
let filename = 'File.pdf';
let _file = new File([blob], filename);
let cv = new sforce.SObject('ContentVersion');
cv.Title = filename;
cv.PathOnClient = filename;
cv.VersionData = blob;
cv.VersionData = cv.VersionData.substring(dataStart);
cv.ContentLocation = 'S';
let result = await sforce.connection.create([cv]);
console.log('result > ', result);
But file in ContentVersion is wrong. Any ideas?
Upd.: an interesting thing: if I'll set js debugs and try to download file locally (not to sf) - then I can do it. But only with debug points