SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question image broken after download from server

    I have a very simple python script to download a jpg image to client, but it always return a broken image.
    Really don't know what's missing. Can anyone help?

    Here is the code:
    Code:
    import sys
    
    filename = r"path\image.jpg"
    sys.stdout.write( "Content-Disposition: attachment; filename=image.jpg\r\n"
    	+ "Content-Type: image/jpeg\r\n\r\n"
    	+ file(filename,"rb").read())
    Here are the images on the server and downloaded:
    index.jpg
    image(1).jpg

  2. #2
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Hi,
    Your carriage returns look Windowsy to me; are you using Windows? If so, this might explain what's going on:
    http://code.activestate.com/recipes/...under-windows/

    so even though you're *reading* a binary file using "rb", you're *writing* a text file when using stdout, even with the attempt at setting MIME type.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •