Comments (8)
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.
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.
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.
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.
Hi Fjellvang and Morten :)
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.
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.
For now I added a note to the part around file uploads:
30fc154
from umbraco.headless.client.nodejs.
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)
- Do the client library work with angular? HOT 10
- Any plan for support of rxjs observables? HOT 2
- Possible error with pageSize and page options, when using client.delivery.content.children HOT 2
- Lack of Documentation HOT 5
- TypeError: Cannot read property 'data' of undefined HOT 1
- Support for TypeScript (typings) HOT 2
- Descendants call should be a PagedResponse in 0.8.0 HOT 1
- Axios dependancy IE11 issue HOT 1
- Is this safe to use? HOT 2
- Support for varying URL configuration HOT 1
- @umbraco/headless-client requires allowSyntheticDefaultImports to be true
- @umbraco/headless-client has CommonJS or AMD dependencies can cause optimization bailouts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umbraco.headless.client.nodejs.