Hey!
I am trying to follow your thoughts and implement image upload to MediaManager via getUploadUrl() . The standard method (via upload () on backend ) does not suit me because of the file size limitations, as you wrote above.
So I have:
- HTML component , that read the selected image and convert it to base64;
- getUploadUrl.jsw on backend, which get an upload link for me;
- And that part
import * as request from 'request-promise-node';
async function uploadImageViaUploadUrl(uploadUrl, uploadToken, contentStream, fileName, contentType) {
const body = {
upload_token: uploadToken,
file: {
value: contentStream, // a Node.js Buffer with the file content
options: {
filename: fileName,
contentType: contentType
}
}
};
const response = await request.post({url: uploadUrl, formData: body, json: true});
return `wix:image://v1/${response[0].file_name}/${response[0].original_file_name}#originWidth=${response[0].width}&originHeight=${response[0].height}`;
}
And my goal is for it to work like this:
The user selects an image, the HTML component requests an upload link, the getUploadUrl.jsw module generates an upload link and sends it back to the HTML component so that the component sends a request to upload the file by this link.
BUT, I don’t know how and where I should use the part with uploadImageViaUploadUrl
?
Also, do I have to fetch smth somewhere to get uploadImageViaUploadUrl work?
How should I do that?
Thanks for any help!