I've created a class extension which allows uploading of an additional file (an image). The attribute name is "headingFile".
I now need to be get the URL for that image so I can display it.
I've been able to get information about the file with: $.getBean("fileManager").readMeta($.content('headingFile')) but can't find how I can get it's URL.
How do I get the URL for a file that has been uploaded with Class extension?
Thanks
Try this
$.getURLForImage(fileid=$.content('headingFile'),size='large')
or
$.getURLForImage(fileid=$.content('headingFile'),width=600,height=300)
Or if it's not an image and you just want to download it
$.getURLForFile(fileid=$.content('headingFile'),method='inline')
or
$.getURLForFile(fileid=$.content('headingFile'),method='attachment')
Related
I'd like to add the following attribute to the tag on the django file upload form as part of a progress bar implementation:
onchange="uploadFile()"
Do you know how I would be able to modify the default file upload input with this assignment?
You'll want to add the following to your form: field.widget.attrs["onchange"]="uploadFile()"
And include the javascript somewhere within the template being used.
Am using Carrierwave gem to upload the file.
I need to validate the file while uploading ,it should accept only pdf,jpg and png.
Is there solution to do clientside validation.
The HTML input element has an accept attribute you can use to filter by file type. http://www.w3schools.com/tags/att_input_accept.asp
You can also validate by file extension using something like http://jqueryvalidation.org/extension-method/
This does not prevent a malicious user from uploading a different file type than intended, so you should still validate it after uploading using something like https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/processing/mime_types.rb
I am trying to use Cloudinary as a CDN and am having some trouble getting file uploads to work properly. I have followed their blog posts and website, but am running into a consistent and very annoying error.
I have a model associated with both an image (a cover photo) and a media object (a PDF or ebook, like a .mobi or .epub). I have a model form set up to create an object:
class NewMediaObjectForm(forms.ModelForm):
class Meta:
model = MediaObject
fields = ('cover_photo', ...)
cover_photo = CloudinaryJsFileField(options={'tags': 'cover_photo'})
Now, I've read this tutorial from Cloudinary and I know that their form looks like this:
class NewMediaObjectForm(forms.ModelForm):
class Meta:
model = MediaObject
fields = ('cover_photo', ...)
cover_photo = CloudinaryJsFileField(options={'tags': 'cover_photo'})
Here's my problem: if I match their level of indention, the generated HTML shows that the input field is getting all of the right Cloudinary stuff attached to it - but the upload itself doesn't work. The page simply refreshes with an error message stating that no image was selected. Importantly, I can see from the generated HTML that the tags I've specified are coming through.
If I use method #1, with my indention, the file uploads to Cloudinary but none of my tags are applied. It also treats everything as an image, giving me a "invalid image file" error when trying to upload anything other than images (such as the ebook files I mentioned earlier).
I want both - how can I get this upload field to work AND get it to respect the options I'm trying to define?
(I do have cloudinary.config called in the appropriate views; I do have cloudinary_includes and cloudinary_js_config in the appropriate templates; I've imported everything and am calling cl_init_js_callbacks on the form in the view.)
One more addition - I am running this on a local machine using manage.py's runserver rather than deploying, if that has any impact on the configuration.
UPDATE:
I found something I was doing wrong. I've fixed it and made things worse.
The necessary jQuery was not being loaded. Now I am loading it, but the upload button simply doesn't function. I press the button, I select the file, the select dialog disappears, and it shows that no file has been selected. However, I can see that the tags are being passed to the generated HTML, so it's a step in the right direction. Any ideas?
Please forgive me. This was a PEBCAK issue; I will leave this visible for anyone else who may make the same mistakes I've made in the future.
Make sure the proper jQuery scripts are being loaded - open the Chrome developer console, Firebug, whatever and double check. Then, make sure they're being loaded after the DOM so that there are elements for the script to attach to.
Cloudinary will expect html/cloudinary_cors.htmlto be accessible in your static directory.
Either I have broken something, or the default behavior for this particular type of ModelField is to simply IMMEDIATELY upload the selected file and continue displaying "No File Chosen." I thought that nothing was happening and was very surprised when I saw 50+ images successfully uploaded.
Guy
now i want to upload file with rails 4
my problem now i can't check the file extension before upload it
Note : I can upload the file well but i want to get the file kind before upload it
because i need the extension in another step in my App.
I'm tried to use the commands
File.extname(params[:Upload])
but always got the error
can't convert ActionDispatch::Http::UploadedFile into String
also how i can get the file base name before upload it ??
when i tryed to use
File.basename(params[:Upload])
i got the same error
can't convert ActionDispatch::Http::UploadedFile into String
also when i tried to convert the name to Sting i don't get any thing
That's because File.extname expects a string file name, but an uploaded file (your params[:upload] is an object, it's an instance of the ActionDispatch::Http::UploadedFile class (kind of a temporary file)
To fix the problem you need to call the path property on your params[:upload] object, kind of like that
File.extname(params[:Upload].path)
Btw, if you're trying to get the type of the uploaded file, I'd encourage you to check for the params[:Upload].content_type instead, it's harder to spoof
You can use this:
params[:Upload].original_filename.split('.').last
The original_filename contains full filename with extension.
so you split it based on '.' and last index will contain the file extension.
For Example:
"my_file.doc.pdf".split('.').last # => 'pdf'
You can check this for more info ActionDispatch::Http::UploadedFile.
I'm trying to set up permission checking to static files uploaded by users. To do this, I use the path requested to get the media object which represents the file. I also use sorl-thumbnail library to make thumbnails. I use get_thumbnail() function to get the cached thumbnail from an url of the original uploaded picture. Is there any way of doing the inverse operation? from a cached image url, can i have the original url? something like:
picture = Image.objects.get(url=get_original('/cached/url/of/the/thumbnail/image'))
There is no default way to do this. Sorl thumbnail generates the path for the new thumbnail by creating a hash of the original file name along with the options you have specified so there is no easy way to reverse that operation. You could create a DB table the maps the original image file to your current thumbnail and keeps it up to date everytime the dimensions etc. change.