I'm uploading files using fancy upload. Back end is in Java Servlet. How to retrieve file meta info, such as: name and mimeType. Servlet Request parameters are empty. How can it be achieved? How to pass parameters?
Related
I have quite a few PDF files which are stored as private on an AWS S3 storage.
I'm creating a url to access the pdf through python boto library (with signature and signed headers) and successfully able to access the files if I just provide the PDF file name. But I need to access these PDF files at a particular page and with some additional parameters (bold highlighted). e.g:
https://mybucket.amazonaws.com/media/private/xyz.pdf#page=6&zoom=100&toolbar=0&navpanes=0&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=***********************&X-Amz-Date=20180925T044257Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&X-Amz-Signature=a9ba6473464trdfghf76c578475hdfjdbv792cf7f1193fe8a274549
When I try to access the file with additional params, it gives me 'Resource not found" error but without the params, it accessible.
Can anyone guide me to achieve this goal ?
SOLVED:
The issue was that we need to append the PDF arguments after the signature in the url.
In my case it was:
https://mybucket.amazonaws.com/media/private/xyz.pdf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=***********************&X-Amz-Date=20180925T044257Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&X-Amz-Signature=a9ba6473464trdfghf76c578475hdfjdbv792cf7f1193fe8a274549#page=6&zoom=100&toolbar=0&navpanes=0
When I try to download the text file in sensenet, the text file will open in browser but not downloaded, could you give some suggestions about how to set to download text file directly?
It's handled by the browser. If it can open a certain file type, then it will show it instead of downloading.
On server side you can force to download file types on your website if your http handler use disposition when set response stream:
response.AppendHeader("Content-Disposition", "attachment");
With sensenet you have to write your own http handler or modify ProcessRequest of SenseNetStaticFileHandler.cs.
MSDN is not too helpful on this topic, but you can find some information on this here.
On client side there is another solution, if you can change the html code of the link. With html5 <a> tag has got a download attribute that forces the linked file to download instead of navigate the browser to it. It works if the browser supports it. See HTML download Attribute.
I am using PhantomJS 1.9.7 to scrape a web page. I need to send the returned page content to S3. I am currently using the filesystem module included with PhantomJS to save to the local file system and using a php script to scan the directory and ship the files off to S3. I would like to completely bypass the local filesystem and send the files directly from PhantomJS to S3. I could not find a direct way to do this within PhantomJS.
I toyed with the idea of using the child_process module and pass in the content as an argument, like so:
var execFile = require("child_process").execFile;
var page = require('webpage').create();
var content = page.content;
execFile('php', '[path/to/script.php, content]', null, function(err,stdout,stdin){
console.log("execFileSTDOUT:", JSON.stringify(stdout));
console.log("execFileSTDERR:", JSON.stringify(stderr));
});
which would call a php script directly to accomplish the upload. This will require using an additional process to call a CLI command. I am not comfortable with having another asynchronous process running. What I am looking for is a way to send the content directly to S3 from the PhantomJS script similar to what the filesystem module does with the local filesystem.
Any ideas as to how to accomplish this would be appreciated. Thanks!
You could just create and open another page and point it to your S3 service. Amazon S3 has a REST API and a SOAP API and REST seems easier.
For SOAP you will have to manually build the request. The only problem might be the wrong content-type. Though it looks as if it was implemented, but I cannot find a reference in the documentation.
You could also create a form in the page context and send the file that way.
What is the best practice to implement file uploads using Restler framework?
I like to have a API call that get the file save it in CDN and return back the CDN file URL to the caller. What is the best way to implement it?
File upload to CDN using our API
This requires two steps, first is to get the file on the API server.
add UploadFormat to the supported formats
Adjust the static properties of UploadFormat to suit your need
From your api method use $_FILES and move_uploaded_file to get the file to the desired folder. This step is common for any php upload process.
Now that you have the file on the server
Upload it to CDN. You can use any means provided my your CDN. It can be ftp or using some SDK to do the upload
Construct the CDN url and return it to the client
I'm building a web server as an exercise. When I receive a raw request, it gets parsed into an simple syntax tree, and a response is built by evaluating this tree. My question this: When sending an HTTP Response, does the Content-Type field get set by taking the file extension of the requested resource and looking it up in a dictionary of MIME-types? A good example would be the anatomy of how the response for a favicon.ico is built. Any insight into this would be most helpful. Thanks.
By default, web server looks into file extension and select what kind of Content Type it should interpret the file as. However, server-side scripting can send custom header ( e.g. header() function of PHP ) to override the settings . For example, a JPEG can be interpreted as PNG if you send Content Type as image/png to web server with the following code:
header('Content-Type: image/png');
For non-file requests, the web server looks into custom header directly.
Web server maps extension with MIME type. As you tag apache, Apache uses AddType directive to identify file's MIME type, while IIS and other web servers have similar settings .