2

I have some code that creates a zip file of some image and then right after that code it tries to download the file. This works fine when the zip file is very small but when it is larger it tries to download the file before it is actually completed being created.

So something like this

<CFZIP code here>

<cfset TheFileName = "#ReReplace(GetImage.ItemNum, " ", "-", "ALL")#.zip">

<cfheader name="Content-disposition" value="attachment;filename=#TheFileName#">
<cfcontent type="application/zip, application/x-zip, application/x-zip-compressed, application/octet-stream, application/x-compress, application/x-compressed, multipart/x-zip" file="#APPLICATION.ProductImageDirectory#\full-brands\#TheFileName#">
Renshi
  • 77
  • 7
  • 1
    That would suggest that the zip operation is asynchronous i.e. done in a separate thread. Just to confirm this, add `` after your ``. This will make the responding thread wait 10 seconds before responding to the client. If that helps with your issue, we shall discuss a better way to solve this. – Alex Feb 16 '18 at 22:01
  • I have tried the sleep function to no avail. The actual zip file is created in less than a second. It still seems to try to download a partial file. The zip might be 6mb but the file it tries to download with or without the sleep function is only like 128kb – Renshi Feb 17 '18 at 04:57
  • Check with your web-/fileserver then as it seems to be a transfer issue. – Alex Feb 17 '18 at 13:06

2 Answers2

0

A couple of issues with your code.

Firstly, your mime-type list should be separated by a semicolon ; instead of a comma , as documented here.

So instead of this

<cfcontent type="application/zip, application/x-zip, application/x-zip-compressed, application/octet-stream, application/x-compress, application/x-compressed, multipart/x-zip" file="#APPLICATION.ProductImageDirectory#\full-brands\#TheFileName#">

Your should change it to this

<cfcontent type="application/zip; application/x-zip; application/x-zip-compressed; application/octet-stream; application/x-compress; application/x-compressed; multipart/x-zip" file="#APPLICATION.ProductImageDirectory#\full-brands\#TheFileName#">

Secondly, while this might not be an issue, but it seems like you have some serious mime-type overkill going on in your <cfcontent> tag. Since I don't really know, I can't really say that you should remove any of them. However, I'm not sure if any in your list might have a conflict with others? I've personally only used just application/x-zip-compressed and it seems to work just fine. So the bottom line is perhaps tweak and experiment to find what works best.

Good luck and hope this helps.

user9263373
  • 1,054
  • 8
  • 15
  • Thanks for the semicolon information. I tried that but still no luck. also tried just making it application/x-zip-compressed and no luck. Not sure what is going on here :( – Renshi Feb 18 '18 at 23:53
  • @Renshi I noticed in one of your comments that the file size is always 128kb. Have you inspected the contents of the file after it's downloaded? That might lead you to more clues. – user9263373 Feb 19 '18 at 00:10
  • For more debugging try this, after your `` code, comment out your `` and `` and add these two lines to inspect your zip file contents `` `` and see what it displays. – user9263373 Feb 19 '18 at 00:36
-1

I found the issue. I was writing the zip file to one directory and then trying to download it from another. The strange thing was I would have expected a 404 not found message but it basically just delivered me an empty zip file anyway. Either way, problem solved.

Renshi
  • 77
  • 7
  • (update) An invalid path or missing "file" would produce a 500 error. Also, the cfcontent should only use a single "content-type" like user9263373 said – SOS Feb 20 '18 at 20:53