How to upload from BUFFER?

@russian-dima

Hello!
I solve this via your solution
(like this

  1. Creating an HTML-Component-File-Selector, which gather all needed informations including the base-64-code.
  2. Sending all gathered data to your site.
  3. Using the provided code from the Wix-Api on back-end (send DATA to backend).
  4. Handle the data on backend.)

But this way I can send only 2-3MB image (for larger images I get Uncaught in promise ), and for larger images as I understand i need to use getUploadUrl to create link to upload by performing a POST operation to that URL.
BUT apparently

import * as request from 'request-promise';

const response =await request.post({url: uploadUrl, formData: body, json:true});

this construction doesn’t work anymore.
request-promise was deprecated
And now I try to use node-fetch npm

import fetch from 'node-fetch';

export async function uploadImageViaUploadUrl(uploadUrl, uploadToken, contentStream, fileName, contentType) {
  let buf = Buffer.from(contentStream, "base64");
  const body = {
    upload_token: uploadToken,
    file: {
      value: buf, // a Node.js Buffer with the file content
      options: {
        filename: fileName,
        contentType: contentType
      }
    }
  };
  await fetch( uploadUrl, {
  method: 'post',
  body: JSON.stringify(body),
  headers: {'Content-Type': contentType}
  })
  .then( (httpResponse) => {
    if (httpResponse.ok) {
      return httpResponse.json();
    } else {
      return Promise.reject("Fetch did not succeed");
    }
  } )
  .then( (json) => console.log(json.someKey) )
  .catch(err => console.log(err));

But no luck here, all I get is Fetch did not succeed.
I think the problem is in node-fetch or my fetch creation.
Stuck here.