I'm trying to use an post call to a get some data from a php file. I know the code works because I'm using it on another computer and it works fine. Every time I make a call I get this error.
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(XHR)POST - http://localhost/PhpProject4/newEmptyPHP.php
This is from MS edge. The php file is in the same directory as the html file and the file making the call. I think it has to do with my xampp server. Any Ideas? Also this is all on my local machine.
Just check your .htaccess file, maybe mod_rewrite changes adress
Related
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.
So all uploads for my app are not stored in my web server space, they are stored in a file system storage. When my users want access to the file they call a URL and the backend process will buffer the data to the browser via the HttpServletResponse outputstream. This works great as intended for downloading a file. Now my use-case has a scenario where I need to load an embedded object using this same method.
I am essentially loading a preview of the PDF file in the browser. This works fine if the PDF is stored on the web server and I provide a direct URL to the file. But when I use my method of sending files to the user then it doesn't work.
<object data='"+pdfUrl+"' type='application/pdf' width='160px' height='160px' />
If i put pdfURL into a browser my file gets downloaded no problem. So I think the issue is the HTTP headers I am sending in the outputstream that maybe is preventing the Object from loading properly. I am not sure if maybe its expecting something specific to be set in order to trigger loading the file
I am currently using very basic headers as follows:
BufferedInputStream is = <Some File Inputstream>;
resp.setContentType(new MimetypesFileTypeMap().getContentType(directory+filename));
resp.setHeader("Content-Disposition", "attachment; filename="+StringFormatHelper.formatFileName(filename));
bufferedCopy(is, resp.getOutputStream());
is.close();
resp.getOutputStream().flush();
Anyone have any ideas on what I have to change to get the data to properly load in the Object tag? I don't get any errors in the JS console or server side. I am not sure how to debug this issue.
Edit:
SO i just realized that if i right click on where the blank Object tag is at I have the option to "Save as..." and when I do I download the PDF. So the pdf data is loaded but Its just not displaying in the UI.
The issue is this line of code
resp.setContentType(new MimetypesFileTypeMap().getContentType(directory+filename));
This was not setting the correct mime-type for the file as I thought it was. So there was a mismatch in that the Object tag was looking for application/pdf but the server was sending a different MIME type in the header. Once I matched them up everything worked.
I was able to get the correct MIME type using the Spring provided lookup instead of the JDK lookup
new ConfigurableMimeFileTypeMap().getContentType(directory+filename)
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 have a bit of JavaScript using jQuery that loads data with a quick $.get(url, function(response){ /* ... */}); The data is a straight up text file that is then handled by the JavaScript in that response function.
This has worked for me quite nicely, but I just ran into this problem on my machine: Using the same code, I now get an error saying:
XML Parsing Error: not well-formed Location:
moz-nullprincipal:{74091275-3d54-4959-9613-5005459421ce} Line Number
1, Column 16: image:tiles.png;
---------------^
If I load this from another server, it works perfectly. It's only when I host it on my own PC that I get this error (note that it previously worked perfectly on my own PC as well, which is running Ubuntu and serving the page with Apache). After much headbanging, I found that if I change the extension on the filename I'm loading, it works fine. The file was previously named "test.sprite", and that is when I got the error. If I renamed it to "test.txt" it loads fine.
This error ~seems~ to coincide with a recent upgrade on my system. I upgraded Ubuntu 10.something to 12.04. I'm assuming there was some sort of update in the Apache config that I didn't notice which is causing it to send different headers depending on the extension of the file (the two named here are identical - the .txt is actually just a symlink to the .sprite).
So I have a solution to my immediate problem, but I'd rather not bow to the system's idiosyncrasies. Any idea how I can fix this without renaming the file?
Please note that I'm not an apache expert, but I'll have a crack with pointing you in the right direction.
If undefined, the jQuery AJAX functions will assume the content-type is whatever header Apache has sent back. You can quite simply see what the response is by running your code in Chrome, opening developer tools (Ctrl + Shift + J) and choosing "Network". After clicking on the relevant request you will see the headers coming back, including the content-type.
In your Apache configuration the content-type for the sprite is probably not defined. You can add this with the following line:
AddType 'text/plain; charset=UTF-8' .sprite
This should be in a configuration file parsed by Apache - depending on your version this could be apache.conf, httpd.conf, or another file.
I hope this helps or at least points you in the right direction. Remember to configtest before restarting Apache!
Check out the content-type of the response header, make sure the header you received from the server and your local machine have the same content-type, i.e. same file type , same encoding, something like this: "content-type:text/html; charset=UTF-8".
I am trying to use jquery's ajax $.get(...) function to send a request to my server and have it return some data. I am using the following code:
$.get("php/getRocks.php", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
Instead of getting the the data back, it just returns the entire php file as a string. Am I doing something wrong? Thanks for the help.
Is PHP installed on your server? This is a server issue. For some reason your .php file isn't being handled properly and it is returning the PHP code in plain text.
This is in response to:
Well, I seem to have solved the
problem, sort of. Apparently, if I
access the site localy, php doesn't
work, but if I use the domain name, it
does. Anyone know why? Or better yet,
a way to fix this?
Thanks to everyone for the help!
When working locally (and it always is a good idea to do so before uploading to a live environment) you need to setup PHP on your computer so that it can run the pages you require. A browser will not do it for you as it is a server side technology. You can download a package like Uniform Server, that will give you a full server environment for you to work with.
I have the same problem (using MAMP on mac), and while I haven't solved it, I am a step closer.
Basically, it would appear to have something to do with subdirectories/document root. If I set my url as getRocks.php (and move my script there), it works (I get content back), but if I get it as php/getRocks.php, it does not work (I get the php code back).
Perhaps MAMP is doing something add with response types within subdirectories? Am going to take a further look, but hopefully this helps lead you in the right direction.
Well, I seem to have solved the problem, sort of. Apparently, if I access the site localy, php doesn't work, but if I use the domain name, it does. Anyone know why? Or better yet, a way to fix this?
Thanks to everyone for the help!
1st. make sure you have php installed
If you are using linux / apache2 and php 5
u need to compile/install apache and load php via dso
eg:
LoadModule php5_module modules/libphp5.so
In my humble opinion it has got nothing todo with your jQuery but your web server installation/config:
If it is apache make sure you add this line in your conf file:
AddType application/x-httpd-php .php
More reading about php and apache if you are using php anad apache in linux/nix eg: http://dan.drydog.com/apache2php.html