Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.uploadImage = function (remoteFullPath, localFullPath) {
const imageFile = fs.File.fromPath(localFullPath);
const imageContent = imageFile.readSync();
const metadata = {
filename: imageFile.name,
mimeType: this._getMimeType(imageFile.extension),
size: imageContent.length,
public: true
};
return Kinvey.Files.upload(imageFile, metadata, { timeout: 2147483647 })
.then((uploadedFile) => {
const query = new Kinvey.Query();
query.equalTo("_id", uploadedFile._id);
return Kinvey.Files.find(query);
})
.then((files) => {
if (files && files.length) {
const file = files[0];
file.url = file._downloadURL;
return file;
} else {
Promise.reject(new Error("No items with the given ID could be found."));
}
});
.then((uploadedFile) => {
const query = new Kinvey.Query();
query.equalTo("_id", uploadedFile._id);
return Kinvey.Files.find(query);
})
.then((files) => {