Git Product home page Git Product logo

Comments (8)

Fjellvang avatar Fjellvang commented on June 23, 2024

Hi Pedro.

Just to be 100% sure we're aligned.

You have a url to an image, ie a Jpg and you are trying to upload that image to your umbraco instance via the management API.

For this you've tried to create a piece of media, and/or a piece of content with a media picker.

Did you in this/these calls only supply the URL then, or how did you attempt to upload the image?

from umbraco.headless.client.nodejs.

PMendesWebDev avatar PMendesWebDev commented on June 23, 2024

Hi Fjellvang,

I tried to get the image as a base64 string (to attach it), as a binary data (as per documentation on API) and also to supply a buffer from the image's url.

from umbraco.headless.client.nodejs.

Fjellvang avatar Fjellvang commented on June 23, 2024

How did you attempt it? I think the documentation could be better which i will attempt to alleviate asap but i successfully uploaded an image from a form input with the following code:

var form = new FormData();
const file = e.target.files[0];
const data = 
{
  mediaTypeAlias: 'image', 
  name: file.name,
  umbracoFile: {src: file.name}
};
form.append('content', JSON.stringify(data));
form.append('umbracoFile', file);
client.management.media.create(form);

from umbraco.headless.client.nodejs.

sitereactor avatar sitereactor commented on June 23, 2024

Hi @PMendesWebDev can you help us by elaborating a little bit on what you wrote here

The important thing: in this process, I've felt that some documentation was missing on how we "communicate" with Umbraco Heartcore using the client. The several ways (if there are more than one) of uploading a file; the proper way to relate existing media/content nodes, etc.

Are you refering to the documentation under https://our.umbraco.com/documentation/Umbraco-Heartcore/Client-Libraries/Node-JS/ - being the place to elaborate on using the Management API using the nodejs client with a sample for how to upload media?

It sounds like you found the example in this repository, and that works as @Fjellvang mentioned above. It also sounds like you are trying to upload media that is not local to the nodejs client, so I'm unsure if the question is more about additional ways of being able to upload media or to better document the current approach.

We are happy to help once we have a better understanding of what you are after 😄

from umbraco.headless.client.nodejs.

PMendesWebDev avatar PMendesWebDev commented on June 23, 2024

Hi Fjellvang and Morten :)

@Fjellvang

How did you attempt it?

From the image's URL, using axios, I made a get request and save it as a string (binary and base64) to append it.
i.e.:

var form = new FormData();
const data = 
{
  mediaTypeAlias: 'image', 
  name: {METHOD_ARGUMENT},
  umbracoFile: {src: path.basename(fileUrl)}
};
form.append('content', JSON.stringify(data));
let imageRequest = await axios.get("imageUrl", {responseType: 'arraybuffer'});
let rawImage = Buffer.from(imageRequest.data).toString('base64');
form.append('umbracoFile', rawImage);

@sitereactor
What I meant was, from the example above, I don't know what types the "rawImage" variable can be in order to be successfully uploaded, because the example in the repo only had FileSystem.createReadStream().

I think this could be improved by stating what are the types Umbraco is expecting to receive in the FormData's 'umbracoFile' field.

Thank you both!

from umbraco.headless.client.nodejs.

sitereactor avatar sitereactor commented on June 23, 2024

Alright, before we update anything. Did you want to make a suggestion? Maybe a PR with updated examples?
We are happy to review and merge additional examples that help by imrpving what we have or showing other approaches to uploading files as part of creating a media item.

from umbraco.headless.client.nodejs.

sitereactor avatar sitereactor commented on June 23, 2024

For now I added a note to the part around file uploads:
30fc154

from umbraco.headless.client.nodejs.

PMendesWebDev avatar PMendesWebDev commented on June 23, 2024

Hey there @sitereactor,

Sorry for the absence of answer, I was not available last week. I think the note you added is really the only thing to be done as far as I know, because I did not find any other way to upload the file xD

If, by any chance, I find a working alternative to upload the file, I'll do a PR on the file you edited :)

from umbraco.headless.client.nodejs.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.