I have the following html on a form:
<input type="file" name="uploadField" />
When users click on the browse button they can select any file but I want to rename the file using the value of another field on the form
I have a submit button. Can I do it here?
Can I do it here?
No, for security reasons you have no control of this on the client. You can rename the file on the server when it gets uploaded.
I know the question is old but if anyone is still struggling with similar problem, please try to use append() or set() method of the FormData.
for security reasons you cannot do such thing i.e. manipulate multipart file or file to be uploaded do that on server
Related
I am learning javascript. Can I use javascript to change the browse file path when input type is file?
<input type="file" id="file_input" name="file_name"/>
When I click the "browse file..." button, the window is my assign path.
I do not hope the user to find the file location from the window. I am sorry my poor English
I don't think this is possible. See here for a more complete explanation, but basically it's a security issue. Code from your web page should not be allowed to know anything about the file structure on a client machine.
I need to browse to a folder to get the directory name by clicking a button, is there any way of getting this? I was thinking I could achieve this by using <input type="file" />
For security reasons you cant. You can get just the file name, the rest is handled by the browser.
Answered here https://stackoverflow.com/a/15201258/1248388
More documentation on the File API https://developer.mozilla.org/en/docs/Using_files_from_web_applications
I'm wondering. Is there any way to upload picture to the server with using javascript(jquery)?
And save picture path(name) into database?
I'm running Windows platform server in asp .net 1.1. (I'm remaking 10years old web page) There are absolutely no chance to use php that I know well..
Thanks for all comments, I'm pretty desperate..
You can't directly upload/insert into the database with javascript, you will need some server side code to handle where the file is saved and inserting into the database.
With that said there are a couple options.
First you have traditional forms - <input type="file" />
Secondly you have Drag/Drop and <input type="file" /> dataTransfer object, which contain the base64 encoded version of the binary data from those files. Here is a quick example: http://www.html5rocks.com/en/tutorials/dnd/basics/
Hope that helps!
http://msdn.microsoft.com/en-us/library/aa479405.aspx
The above link details how you can upload a file using ASP.NET. I don't think you necessarily need Javascript/JQuery unless you're doing some validation on the type or trying to do some additional UI stuff with the uploader.
I want to upload a file using Ajax and php. I have a form with <input type="file"> tag. I want when user browses a file and clicks on submit, the file to be uploaded without a refresh. How should I do this ? It does't matter if refresh occur but i want to upload file with help of ajax.
Use a hidden iframe and set your form's target to that iframe's name. This way, when the form is submitted, only the iframe will be refreshed.
Have an event handler registered for the iframe's load event to parse the response.
More details on my blog post: http://blog.manki.in/2011/08/ajax-fie-upload.html
I did it with this jquery plugin. It pretty much mimics standard jquery ajax functionality, but also allows you to send data using iframe. No flash involved, pure javascript.
http://malsup.com/jquery/form/
Here is a file upload example
http://malsup.com/jquery/form/#file-upload
This plugin uses XHR for uploading multiple files with progress-bar in FF3.6+, Safari4+, Chrome and falls back to hidden iframe based upload in other browsers, providing good user experience everywhere.
check this:
http://valums.com/ajax-upload/
Take a look at SWFUpload, it should do what you want.
Here some I found http://blog.insicdesigns.com/2010/02/10-best-ajax-file-uploader-for-your-web-application/
and also jquery upload
plugins
I tried following the example at:
http://www.plupload.com/example_custom.php
But in the request, file is not sent to the method of the controller, only the name.
Maybe I need to set in the configuration of Plupload, something like 'multipart = true'
Any idea?
The question was ages ago. But will answer for other people looking for a solution.
The solution for this is adding "multipart : true" on your pluploadQueue({}) function. That would send the file as multipart. For multiple files, it will send/POST the request multiple times. Then you can handle that on your controller.
Hope this helps.
Jas
I have no experience with Plupload I don't think you should have to explicitly deal with multipart uploads in the plugin configuration. (That is a file uploader library after all.) Don't get me wrong but do you have the multipart attribute set to true in the html markup?
W3C states this for file upload...
<FORM action="http://server.com/cgi/handle"
enctype="multipart/form-data"
method="post">
<P>
What is your name? <INPUT type="text" name="submit-name"><BR>
What files are you sending? <INPUT type="file" name="files"><BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</FORM>
Can we see some more code. There's a lot that could be going wrong.
Also, can you use debugger after the form submission and post a params output here?
J
P.s. By the way, tried to make this a comment but no go...
A few "any" ideas... :-p
Is there any chance the file you try to upload gets filtered by some security feature in Rails, the rails-proxying server (apache?), or even some software on clientside?
Did you try different browsers, to verify it's not a clientside problem? (sniffing your network connection could be another way to verify that the file actually gets sent to the server)
If you happen to be using rack, then there is some middleware that can take care of file uploads for you. Not what you wanted, but perhaps useful as a temporary workaround while waiting in case you'd discover you have to wait for some bugfixing in rails or plupload.
Permissions on the folder where uploaded files are supposed to go? Or do they go in memory first, and write to disk later? Maybe the plupload library uses temporary files somewhere and the permissions aren't working out there.