tracker issue : CF-4204030

select a category, or use search below
(searches all categories and all time range)
Title:

[ANeff] Bug for: S3 Content-Type always application/octet-stream on first write

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/Fixed

Reporter/Name(from Bugbase): Aaron N. / ()

Created: 02/17/2019

Components: File Management, VFS-S3

Versions: 2016,2018

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: 2018.0.0.310739 / 2020.0.0.314573

Priority/Frequency: Normal / Some users will encounter

Locale/System: / Windows 10 64 bit

Vote Count: 0

Issue: S3 Content-Type always application/octet-stream on first write

Repro:

<cfscript>
  myS3Directory = "s3://mybucket";//replace with your bucket name
  if(!directoryExists(myS3Directory)) {
    directoryCreate(myS3Directory);
  }
  
  myImage = imageNew("", 200, 200, "rgb", "blue");
  
  imageWrite(myImage, myS3Directory & '/myJPG.jpg', 1, true);
  writeOutput(storeGetMetadata(myS3Directory & '/myJPG.jpg').content_type & '<br>');//application/octet-stream (bad)
  fileCopy(myS3Directory & '/myJPG.jpg', myS3Directory & '/myJPGCopy.jpg');
  writeOutput(storeGetMetadata(myS3Directory & '/myJPGCopy.jpg').content_type & '<br>');//image/jpeg (good)
  
  imageWrite(myImage, myS3Directory & '/myPNG.png', 1, true);
  writeOutput(storeGetMetadata(myS3Directory & '/myPNG.png').content_type & '<br>');//application/octet-stream (bad)
  fileCopy(myS3Directory & '/myPNG.png', myS3Directory & '/myPNGCopy.png');
  writeOutput(storeGetMetadata(myS3Directory & '/myPNGCopy.png').content_type & '<br>');//image/png (good)
  
  fileWrite(myS3Directory & '/myText.txt', "CF");
  writeOutput(storeGetMetadata(myS3Directory & '/myText.txt').content_type & '<br>');//application/octet-stream (bad)
  fileCopy(myS3Directory & '/myText.txt', myS3Directory & '/myTextCopy.txt');
  writeOutput(storeGetMetadata(myS3Directory & '/myTextCopy.txt').content_type & '<br>');//text/plain (good)
  
  cfimage(action="write", source=myImage, destination=myS3Directory & '/myJPG2.jpg');
  writeOutput(storeGetMetadata(myS3Directory & '/myJPG2.jpg').content_type & '<br>');//application/octet-stream (bad)
  cffile(action="copy", source=myS3Directory & '/myJPG2.jpg', destination=myS3Directory & '/myJPG2Copy.jpg');
  writeOutput(storeGetMetadata(myS3Directory & '/myJPG2Copy.jpg').content_type & '<br>');//image/jpeg (good)
  
  cfimage(action="write", source=myImage, destination=myS3Directory & '/myPNG2.png');
  writeOutput(storeGetMetadata(myS3Directory & '/myPNG2.png').content_type & '<br>');//application/octet-stream (bad)
  cffile(action="copy", source=myS3Directory & '/myPNG2.png', destination=myS3Directory & '/myPNG2Copy.png');
  writeOutput(storeGetMetadata(myS3Directory & '/myPNG2Copy.png').content_type & '<br>');//image/png (good)
  
  cffile(action="write", file=myS3Directory & '/myText2.txt', output="CF");
  writeOutput(storeGetMetadata(myS3Directory & '/myText2.txt').content_type & '<br>');//application/octet-stream (bad)
  cffile(action="copy", source=myS3Directory & '/myText2.txt', destination=myS3Directory & '/myText2Copy.txt');
  writeOutput(storeGetMetadata(myS3Directory & '/myText2Copy.txt').content_type & '<br>');//text/plain (good)
</cfscript>

Attachments:

Comments:

Hi Adobe, I misunderstood the issue. It seems CF is not sending a Content-Type by default, and S3 tries to determine it via file extension and defaults to application/octet-stream. If I, for example, use FileCopy() to copy myText.txt as myText.pdf, then S3's Content-Type becomes "application/pdf" :(. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/ObjectMetadata.html#getContentType-- ----------- When uploading files, the AWS S3 Java client will attempt to determine the correct content type if one hasn't been set yet. Users are responsible for ensuring a suitable content type is set when uploading streams. If no content type is provided and cannot be determined by the filename, the default content type, "application/octet-stream", will be used. ----------- I'm guessing you will say "set the Content-Type manually via StoreSetMetadata()", but my reply would be "IMO, users would find it more useful if CF defaults the Content-Type based on FileGetMIMEType(), thus saving them that step". Then users only need StoreSetMetadata(), for Content-Type, if they're wanting to fake the Content-Type. I hope you would consider, b/c application/octet-stream or file-extension-based Content-Type just isn't very useful (IMO). Thanks!, -Aaron
Comment by Aaron N.
30293 | February 17, 2019 09:07:13 AM GMT