If I use coldfusion's getTempDirectory() as the path to generate a file, is there any way for a browser to access that? Or, if not, can I configure the temp path to be a certain folder?
You could serve the content using the cfcontent tag. It reads the file and sends the contents to the browser.
<cfcontent
type = "text/html"
file = "#getTempDirectory()#\myfile.htm"
deleteFile = "No">
Related
I have a test.txt file stored in an S3 bucket and when i click on "Open", i want it to get downloaded but it is opening in the browser itself. I have tried setting Content-disposition to attachment but it did not work. Is there any way to force download text and json files from S3?
Thanks in advance.
When you click Open in the S3 console, it sends response-content-disposition=inline to S3 which overwrites whatever Content-Disposition set on the object to inline. Content-Disposition: inline indicates that the content of this file can be displayed inside the Web page. This is why setting Content-Disposition won't work in this case.
If you need to download the file (instead of opening it in the web page) from the S3 console, you can either
click Open
on the new popup page, right click and choose Save as ...
Or
click Download as in the S3 web console
I am using boto3 to upload massive media files (2GB+) from my Django website to an s3 storage bucket. My issue is that when uploading a file larger than 2.5MB - the connection is immediately timed out and no debug information displays
I assume what is happening is that Django is using the temporary file upload handler, but the temp file handler won't work on the server the Django app is running on (pythonanywhere free tier).
This works flawlessly locally, because it just has to copy to the OS, not the server. I would like to skip the web server so I am not using all the storage/bandwidth
s3.upload_file needs the local path of the file in order to be able to upload it to S3, the only way I could find to do that is grab the temp_path of the file.
# method to chunk the upload process if file is over 2.4MB
def s3_multipart_upload(f, video_id):
# our server path
file_path = "media/"
new_folder = str(video_id)+"/"
file_name = f.name
server_path = file_path + new_folder + file_name
# the file gets copied to ~/tmp/ so grab that path
local_path = f.temporary_file_path()
# create s3 client connection
s3 = boto3.client('s3', settings.AWS_S3_REGION_NAME, **credentials)
config = TransferConfig(
multipart_threshold=1024 * 25,
max_concurrency=10,multipart_chunksize=1024 * 25,
use_threads=True
)
s3.upload_file(
local_path,
settings.AWS_STORAGE_BUCKET_NAME,
server_path,
ExtraArgs={'ACL': 'public-read'},
Config=config,
Callback = ProgressPercentage(local_path)
)
return
I would like to be able to upload directly to S3, straight from my website, without the files going through the server (python anywhere). If there is a cleaner way of doing this, a better server I should use, or if there is a way to upload the file without copying to temp first - I'm all ears.
(I am also new to Python/Django/Servers in general, so any help is appreciated)
I am not sure if you have found the answer but you can upload content directly to s3 using signed url mechanism.
Request Signed URL for s3 from django backend
Use frontend to upload content directory to s3
But I would suggest do this only if you have bigger media files to be uploaded.
I found this as secured approach.
https://www.serverless.com/blog/s3-one-time-signed-url
I have the following folder structure in my bucket:
Structure: Bucket-Name/YEAR/Folder/Objects
Example Path: mybucket/2018/myEXEs/file.exe
Issue: When I try to download an object (file.exe) from example path above by clicking on the EXE, the filename that appears in the download dialog box looks like this:
"2018%2FmyEXEs%2Ffile.exe"
You have to strip the URL encoded path every time and this is an inconvenience if you do not want to make the URL public.
Observation:
It appears the storage browser adds bucket path to the filename and that gets encoded to replace '/'.
This does not happen when you download the object using public URL.
Question:
Is there a way to strip the URL encoded path from filename?
There is a feature request in the public tracker for this. As mentioned in the same link, there is a workaround by setting the filename in the Content-Disposition metadata of the files. To do it, go to Cloud Storage, edit metadata of a file and, in Content-Disposition field, add:
attachment; filename="filename"
The the only inconvenient with this workaround is that you have to set filenames in all the download files's metadatas.
Is it possible to download a pdf from given url and save it to a server using ColdFusion?
I am looking for a method similar to a file_put_contents() in php and I couldn't find anything in the Adobe documentation.
Thanks!
Yes, you can use the cfhttp tag to download a document from a URL and save it to a file:
Specifically, you'll do something like:
<cfhttp method="get" url="#fileURL#" path="#filePath#" file="#fileName#" />
Given a Coldfusion page generates some content (html, xml, json, whatever) to satisfy a client request, can the onRequestEnd handler read (or write) the content in the response stream? If so, how?
If it matters assume Coldfusion 8 on IIS 6.
Thanks for looking
Adrian
GetPageContext().getCFOutput() seems to do what I need e.g.
<cfset oldContent = GetPageContext().getCFOutput().getString()>
<cfset GetPageContext().getCFOutput().clearBuffer()>
<cfset newContent = ModifyContent(oldContent)>
<cfset GetPageContext().getCFOutput().print(newContent)>
Yes,
According to the docs: ColdFusion 8 onRequestEnd
This method has the same purpose as the onRequestEnd.cfm page. (You
cannot use an onRequestEnd.cfm page if you have an Application.cfc
file for your application.) This method runs before the request
terminates; therefore, it can access the page context, and can
generate output.
This method can access the requested page’s Variables scope only if
the Application.cfc file includes an onRequest method that calls the
page. You can use Request scope variables to share data with the
requested page, even if the Application.cfc file does not have an
onRequest method.