views:

26

answers:

1

Why would that happen?

Its ACL permissions are identical to all the other photos.

These photos are hosted via an S3 bucket, but again, there's nothing different than any of the others.

Here is the file URL:

http://s3.amazonaws.com/hq-photo/root/system/images/340/resized_thumb/Osseo-Endo_System.png?1272485279

It's occurring with two images on the same page.

+2  A: 

You need to set the mime type. File extensions are not used consistently by browsers.

When you store the file, do something like:

opt = [] # default options for the S3Object.Store call. See the method's
         # source for info on all the options
epub =  an_epub_file?(obj) # my private method to determine if I'm storing 
                           # an epub file. 
extname = File.extname(obj) # Gets the suffix from the file name. Eg ".js"
mimes = MIME::Types.type_for(obj) # if the mime library finds anything, an array
                                  # of mime values is returned

mime = (mimes && mimes[0] && mimes[0].content_type) ||  # did we get a value from
                                                        # the mime library?
       (  # Nothing from the mime library. Sigh.
          # Let's try other ways to get the right mime value...
        case
          when epub: "application/epub+zip"
          when extname == ".js" : "application/x-javascript"
          else "application/octet-stream" # default mime value
        end)

opt[:content_type] = mime 
AWS::S3::S3Object.store(obj, data, bucket, opt)

Note that a case expression is being used in the code example. It is NOT a case statement. A case expression uses the matching arm of the case to return a value.

In the assignment statement above, the case expression is evaluated if the left side of the OR expression ends up false or null.

I used a case expression since I anticipate needing to add other specialized mime types in the future.

Larry K
Is your `epub` the same as the .epub` file extensions for the epub readers? Not really sure what you're getting at. Perhaps you know a link I could read? HAving trouble grasping my brain around this.
Trip
Sorry if the above is confusing. Yes, the epub flag is used in my code to say whether a file is an epub file or not. Epub files do not need to have a .epub suffix. Since some ebook readers show the file suffix, you don't want one since it'd look ugly. I've annotated the code above.
Larry K
Its an incredible answer. I really appreciate it. Thank you. I wish I could figure out a way to target the file in the s3 instance. using s3sh, and can't seem to explore sub folders in a bucket. wish i knew some common commands. http://stackoverflow.com/questions/3576832/common-commands-for-exploring-buckets-with-s3sh-or-awss3
Trip
Glad to help. I use the http://timkay.com/aws/ command line tool. Remember that S3 doesn't have subfolders, per se. Rather, it fakes them: the objects include the "subfolder" names and slashes as part of the object's name. Eg object is named "folder_a/foo.png" -- there is no folder_a, just the illusion of a "folder_a"
Larry K