when we have multiple button to upload on a page , I want to upload a file for the 2nd one,we I try to upload so it just upload on the first option.
#browser.file_filed(:type => 'file').set 'path'
upload_button1 upload_button2 upload_button3
Related
I'm new to NopCommerce, whenever I want to delete a image, pdf, video or folder, it gives error, it says "error it cant delete" in Roxy Fileman. I'm using NopCommerce 4.40.3
Any suggestions. Thanks in advance.
I'm new to use cloudinary service.
Uploaded image successfully on cloudinary and get public URL.
But I want to update existing image with new one is there any option on cloudinary to update existing image?
Please suggest me in this.
Thanks in advance :)
Yes, it's possible to update an asset already uploaded into Cloudinary.
To do that, you would need to perform an upload() method call and supply the new asset you want to upload (in the file parameter) and also set the public_id parameter to the existing public_id you want to overwrite. The overwrite parameter as part of the upload() method already defaults to True and that will be all that's needed to replace the old asset in your account with the new one. You should also consider passing the invalidate parameter set to True to tell Cloudinary to purge the CDN cache for the old asset so that existing URLs return the new asset after the update.
Apart from the API, you can overwrite the image via Media Library UI upload as well. To do that you would need to go to your Media Library and use the Upload button to launch the Upload Widget. There you will see an 'Advanced' option at the bottom that will allow you to specify a public_id which you would set to the public_id you want to overwrite and then just drag and drop or select the asset you want to upload. You will get a prompt to confirm the overwrite action before the upload completes.
Click on upload and then click on advanced settings.
Then enter public id same as image you want to replace.
This will update the image with new version id.
Screenshot of uploading with advanced settings
There is a cache in using the upload() function to update the existing image or file:
if you provide a wrong a public_id that doesn't exist in your cloudinary storage then the upload method will create a new file with wrong [The public_id that doesn't exist] public_id.
So to update the existing file, I would like to prefer first destroy the file with the help of destroy() then upload it again.
Note : distroy function always resolve if it can't find the file then it will return { result: 'not found' } else if it successfully deleted the file then it will return { result: 'ok' }.
Step 1. Destroy the image with the help of public_id
const { result } = await cloudinary.v2.uploader.destroy(public_id);
if (result === "not found")
throw new BadRequestError("Please provide correct public_id");
if (result !== "ok")
throw new Error("Try again later.");
});
Step 2. Upload it again.
const myCloud = await cloudinary.v2.uploader.upload(avatar.url, {
public_id: avatar.public_id,
});
console.log(myCloud);
If anyone knows other better solution then please share!!
Thank you
I have a simple reactive form in angular 6 that it also has a file input to upload images.
The scenario is to submit the form, save the image and the text fields of the form and then update a photo gallery with the new image. For a photo gallery, I use the ng carousel.
This is the code in the front-end
<form [formGroup]="myForm" (ngSubmit)="submitForm($event.target)" >
<input type="file" (change)='imageChange($event)' formControlName="imageInput" name = 'imageInput'>
<input type="text" formControlName="imageName" name='imageName'>
<button type="submit" >Submit</button>
</form>
save it like
submitForm(form){
let formData = new FormData(form);
this.http.post('http://localhost:3000/cms/upload',formData,{reportProgress:true,observe:'events'}).subscribe(
event=>{
if(event.type === HttpEventType.Response){
eb = event.body;
this.addpic(eb.data);
}
});
}
eb.data contains data that came from the server, after successfully saving the form data, the id of the new image and its file name.
In addpic I try to add a new image in the carousel. Add all the new data to an array, so I can use the array later, to ngFor it and dynamically create the ng Carousel
addpic(data){
this.images.push({
'id': data.id,
'name': data.name
});
}
use it like so
<ngb-carousel #carousel *ngIf="images" >
<ng-template ngbSlide *ngFor="let im of images; let i = index" id="{{im.id}}">
<img src='../assets/images{{im.newName}}' >
</ng-template>
</ngb-carousel>
So this works fine, but the image is never rendered. I get no errors, I see all the data saved in my database, the image is transferred in the folder as it should, but no new image in the carousel, just a 404 error in the console. The images array is updated, but no image in the carousel. The URL is ok, all the other images with the same URL are rendered in the carousel. It's like the app had no time to see the whole update, so it cannot show the image.
I tried to grab the image file object from the form, save it in angular in a selectedFile: File; and use this in the carousel, but this has no path or anything similar. Grab it when it is set in the form
imageChange(e){
this.selectedFile = e.target.files[0];
}
and use it in addpic
addpic(data){
this.images.push({
'id': data.id,
'name': this.selectedFile.path
});
}
I also tried to use the formData before the form submission, t get the image, but the result is the same, an object with no path.
I also tried to "read" the file using HTML5 FileReader, but this is an image and in the carousel, I need to provide a URL for the src, not just the image file.
I also used formidable in the node to parse the form and take the path of the image, return it back in the front-end along with the id and the file name and use that as an src. But this won't be used by the browser for security reasons I guess, because it is a URL in the temp files.
I also tried to get all the images from the server with a query, but the new image is still not available, giving a 404 error, even though the image is in the folder and the database is updated.
like this
addpic(data){
this.getImages(this.currentId); //get all images again
this.images.push({
'id': this.images.id,
'name': this.images.path
});
}
I have to refresh the page for the image to show. I don't know how to fix this. Any ideas? Is it a security issue that I cannot get the image right away, even though it is saved and I have to refresh? I would like to avoid performing an extra get, if it is possible, to keep client-server communication minimum.
I use angular6 and node 8.11. in windows 10, all locally in my laptop.
Thanks
Might be issue related to updated variable refers to same reference. inside addPic(). add this line of code as last line.
this.images = this.images.slice();
I want don't show thumbnail when i upload images. How can i remove it ?
Example : https://lh3.googleusercontent.com/-nWDNS4695Lg/UtTy3-c9y2I/AAAAAAAAArY/USGOIL43Iyg/w979-h314-no/Capture4.PNG (sr, i can't show image in here)
Anymore, i want just upload one image in one time. Clearly, when i choose file A (not click upload or cancel) and then i choose file B, i want replace file B to file A (Panel upload file just show final file choose, file B). How can i do that ? Follow example picture, it just show $RBLX1U4.jpg to upload or cancel
you just use
<p:fileUpload value="#{bean.file}" mode="simple"/>
It allows only single file upload without thumbnail of the doc.
My packaged app gets images from google drive and then display them on the side. But I can't get the images to be displayed. I am trying to get the url of the image so that I can put that url in an image source. The image url that I am getting is actually an html page rather than jpeg, png etc. I have looked at the reference guide for google picker but nothing seems to work.
I am using this
function pickerCallback(data) {
if (data.action == google.picker.Action.PICKED) {
var fileId = data.docs[0].id;
fileName = data.docs[0].name;
imgURL = data.docs[0].url;
}
I want to use imgURL as the source for image selection but imgURL is not something like "https//:www.example.com/image.jpg. It is rather an html page I want something that ends with file type only then it will be able to display the image. Please let me know how can I get the image to be displayed in html page of my packaged app after selecting it from google drive.
You should fetch the metadata of the image, then use the webContentLink of the image, then the user can view it in a logged in browser. See the documentation on downloads for more information.