You need to sign in to do that
Don't have an account?
User Seth
How to get the original url of a Image Uploaded
I have one LWC can be used to upload a Image and display the image
HTML:
<template>
<input type="file" name="image" id="file" onchange={loadFile} style="display: none;">
<label for="file" style="cursor: pointer;">Upload</label>
<img id="output" width="200" />
</template>
JS:
loadFile(event) {
var image = this.template.querySelector('img');
image.src = URL.createObjectURL(event.target.files[0]);
console.log(image.src);
console.log(image);
}
This is giving temporary url of the image uploaded.
This url I am getting in the console is not working when I put that in Image Src tag in a separate LWC component.
How to get the original image url uploaded.
So that I can store this url in Custom field and show the image based on that url in that field. when any new image uploaded I will change url in the custom field and show new image based on that irl in that Custom Field(URL).
HTML:
<template>
<input type="file" name="image" id="file" onchange={loadFile} style="display: none;">
<label for="file" style="cursor: pointer;">Upload</label>
<img id="output" width="200" />
</template>
JS:
loadFile(event) {
var image = this.template.querySelector('img');
image.src = URL.createObjectURL(event.target.files[0]);
console.log(image.src);
console.log(image);
}
This is giving temporary url of the image uploaded.
This url I am getting in the console is not working when I put that in Image Src tag in a separate LWC component.
How to get the original image url uploaded.
So that I can store this url in Custom field and show the image based on that url in that field. when any new image uploaded I will change url in the custom field and show new image based on that irl in that Custom Field(URL).
Create a custom field in the record to store the file's URL.
When you upload the file, use the ContentVersion object to create a new version of the file and get the associated ContentDocumentId
Use the ContentDocumentLink object to create a new link between the ContentDocumentId and the record, and set the visibility to "All".
Get the URL of the file using the ContentDocumentLink object and store it in the custom field.