arc_ecto icon indicating copy to clipboard operation
arc_ecto copied to clipboard

Original filename is not available

Open jfrolich opened this issue 9 years ago • 3 comments

When I save my file under a different name as the original file name, and I want to use the content_disposition header to serve the right file name, I can do that using s3_object_headers():

  def s3_object_headers(version, {file, scope}) do
    [
      content_disposition: "attachment; filename=#{scope.file}"
    ]
  end

However we have one problem. The filename is not yet available in the scope, and file also does not provide the original file name. I assume this is a bug (can we pass an up to date scope?), and otherwise how can we access the original filename?

jfrolich avatar Oct 20 '16 06:10 jfrolich

I believe file should have the original filename. What does it have instead? Can you show a printout of what you're seeing for file?

stavro avatar Oct 20 '16 20:10 stavro

I set a storage filename for the version as below, so file_name gives me that.

  def filename(version, {file, scope}) do
    version
  end

jfrolich avatar Oct 21 '16 02:10 jfrolich

I think that this would be great in the case that we want the preserve the original filename. S3 doesn't permit all utf-8 characters in the object key (http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html). So some file names are not supported by arc_ecto, forcing us to generate a key that is different from the file name.

If we want to keep the original filename, it could be done by adding the content_disposition header with the old filename. However the file that we get in the s3_object_headers function is the key and the the original filename.

Here is the file that I get in the filename function:

%Arc.File{binary: nil, file_name: "file with spaces.pdf",
 path: "/var/folders/3d/0bcszqq14k565g0sqxghlmcm0000gp/T//plug-1504/multipart-147189-189235-5"}

And here is the file in the s3_object_headers function.

%Arc.File{binary: nil, file_name: "filewithspaces.pdf",
 path: "/var/folders/3d/0bcszqq14k565g0sqxghlmcm0000gp/T//plug-1504/multipart-147189-189235-5"}

martinos avatar Aug 31 '17 02:08 martinos