I need to read a local file and post it to the server, we do not need to choose the file. The path of the file is given.
uploading a file when user manually selects works but in the above scenario we need to read an existing file and post it.
I generally just require the file and upload it.
var file = require('path');
Related
I need to manage some files who are uploaded to my server, but I need to get the URL of the selected file. I know you can't do this with javascript with files outside the server, but I wanna know if there's a way to get the URL from files in the server. For example I got this image from my file input with a selected file (LTAIPBCS75FI.xls) who is hosted in "xls/ITAI2016/Fraccion01/" in my home directory. I get this URL from php:
URL IN FILE INPUT
I need then to get the full directory when I select a file in my server.
I want to import data from a path in an input type file.
It is in use in the kendo UI, and when I wrote the article, I uploaded the data to the spreadsheet by using the file upload window and saved the data to the server.
Therefore, the file is stored in the server-specified path, and DB contains basic information such as file path, file name, and extension.
When I read a post using this, it was successful to retrieve the information of the file from the DB, but it is not in the reading part of the file.
So, I do not upload the file from the input type file that I used at the time of writing, but I want to read the file information from fromfile.
If you know how to do it, please let me know.
This is the code I used to write.
<input class="icon_input_file" type="file" id="insertFile" name="insertFile"/>
$("#insertFile").on("change", function(){
var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
spreadsheet.fromFile(this.files[0]);
});
I'm trying to modify the project so I could plug in a file path or a file as a variable instead of the user choosing the model file. So I'm looking for where the actual upload happens.
In submitProject():
https://github.com/cyrillef/extract.autodesk.io/blob/master/www/js/app.js#L129
I see that it just sends (with an ajax request) an object that holds the file name and unique identifier but not the actual binary file.
In here:
https://github.com/cyrillef/extract.autodesk.io/blob/master/www/js/upload-flow.js#L34
there's r.upload(), is this the actual upload of the model?
Does it start to upload the file right as you press ok in the file chooser?
Is there a way to give it a file path to upload instead of uploading with the form and file chooser?
The author of this sample should be on Christmas vacation, I just downloaded and setup the extractor sample on my machine, with a little debug into the code, let me try to answer as much as I can.
In general, I think some of your understanding is correct, but let me explain a little more:
For a local file to be uploaded and translated, there are actually 2 steps of actual “upload”.
As you mentioned, when you press ok in the file chooser, yes, the file will be first uploaded to the "extractor" server as you noticed by some methods like r.upload(), it’s actually using a JavaScript library call “flow.js", which provides multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API. I am not expert on this, but you can check that module about how to use it to upload a file.
By now, your file is uploaded from client to the "extractor" server, but if you want to translate the file to "svf", the file is required to be uploaded to Autodesk Server(OSS), that is done by clicking “submit my project” buton, when you click this button, as you mentioned, from client, it will call the method submitProject() in https://github.com/cyrillef/extract.autodesk.io/blob/master/www/js/app.js, this method will send a post request of “/api/projects” to the "extractor" server, if you check the code at server side https://github.com/cyrillef/extract.autodesk.io/blob/master/server/projects.js , you can see the extractor server actually upload the file to Autodesk OSS, and then triggers the translation service.
This feature (passing a URL string vs a file binary) is already implemented. You can use the uri: edit box and paste your file URL there. It supports http(s) or S3 uri with access token.
The physical upload happens in this file, whereas the SubmitProject() code sends only information as JSON. The JSON object only contains a reference to the file which was uploaded using flow.js. But would contain the uri string if you had choose that method.
I have a file in the C: drive
'C:/myFile.txt'
I know the path and I simply want the user to save the file. However I try to use javascript
window.location.assign('C:/myFile.txt');
I get the path name not being understood.
I also try
window.open('C:/myFile.txt');
So I was thinking to send an AJAX request to PHP, supply the path, and use fopen. I do that and pretty much nothing happens. I need it to prompt as a download/save as.
If this server is remote to the user, they will not be able to download a file with a path from your C: drive in their browser.
You will need to place the file somewhere in your web root and then use its URL for downloading: window.location.assign('http://www.example.com/myFile.txt');
I am using SWFUpload to allow users to upload multiple files in any browser. A user can provide custom file names for the files being uploaded. How can I iterate through all the queued files and update the name of the file to the custom name before the file is uploaded.
If I can't change the file name, how do I add a post parameter to each file being uploaded to make the change on the server side? I know how to add parameters for all files but how would I do it for each file?
You can't update the actual name of the file that gets sent in the POST body of the file upload because internally, SWFUpload is using a FileReference which doesn't let you change any of the file's properties before uploading it (and there's no way to get proper upload progress without using a FileReference to do the uploading, so this isn't something that can really be changed).
However, you should be able to add an extra POST parameter per file via the addFileParam function. Its signature is:
addFileParam(file_id:String, name:String, value:String):Boolean