Changing default file upload input - django

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.

Related

Load files from folder with a custom query with power BI

I am trying to load csv files from a folder but I need to apply several custom steps to each file, including dropping the PromoteHeaders default.
I have a custom query that can load a single file successfully. How do I turn it into a query that loads all files in a folder?
By default, File.folder's "promoteHeaders" messes up my data because of a missing column name (which my custom query fixes).
The easiest way to create a function that reads a specific template of file is to actually do it. Just create the M to read it and by right click on the entity transform it to a function.
After that is really simple to transform your M so it uses parameters.
You can create a blank query and replace the code with this on as an example, customize with more steps to deal with your file requirements.
= (myFile) => let
Source = Csv.Document(myFile,[Delimiter=",", Columns=33, Encoding=1252, QuoteStyle=QuoteStyle.None])
in
Source
And then Invoke Custom Function for each file with the content as the parameter.

Validation for file type

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

rails4 upload file extension error ActionDispatch::Http::UploadedFile

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.

Mura CMS - Displaying a Class Extension File

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')

Adding class attribute to osCommerce tep_image function

I'm trying to make my product image format a certain way using CSS, but I'm not sure where to add the following code to the tep_image function call:
class="single-product"
I want the generated image to have the extra class attribute included as part of its HTML.
I'm hoping I don't have to add an if statement to the constructor class.
The tep_image function is located in \includes\functions\html_output.php.
tep_image(DIR_WS_IMAGES . $product_info['products_image'],
addslashes($product_info['products_name']),
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT,
'class="single-product"')
Any extra attributes you need to add to the image function will be after setting the image dimensions, so place the CSS as the fifth parameter.