Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWSS3 0 byte downloads #543

Closed
sergeh opened this issue Aug 19, 2015 · 7 comments
Closed

AWSS3 0 byte downloads #543

sergeh opened this issue Aug 19, 2015 · 7 comments

Comments

@sergeh
Copy link

sergeh commented Aug 19, 2015

I'm not exactly sure what I'm doing wrong but for some reason when I try to force a download it returns a 0 byte file even though the file is in the bucket. Uploading files to the bucket works fine.

Here's what I have for forcing a download via ajax when a user clicks a button

  $exists = Flysystem::has($file_path);

  if ($exists) {
    $stream = Flysystem::readStream($file_path);
    return Response::stream(function() use($stream) {
        fpassthru($stream);
    }, 200, [
        'Content-Type' => Flysystem::getMimetype($file_path),
        "Content-Length: " => Flysystem::getSize($file_path),
        "Content-disposition" => "attachment; filename=\"" . basename($file_path) . "\"",
    ]);
  }

getSize and getMimetype return the correct info but stream_get_contents($stream) returns null, any ideas why?

@frankdejonge
Copy link
Member

@sergeh Hi, which adapter are you using, v2 or v3?

@GrahamCampbell
Copy link
Member

Look at this line: fpassthru($stream);. You forgot a return.

@sergeh
Copy link
Author

sergeh commented Aug 19, 2015

@frankdejonge I'm using v2 but I think I figured the solution, removing the :from "Content-Length:" seems to have worked, running some more tests and will report back

@frankdejonge
Copy link
Member

@GrahamCampbell that's not needed, it's a function to output a resource.

@frankdejonge
Copy link
Member

@sergeh well, that sounds pretty reasonable. It probably caused a malformed header to be returned, causing recipient to error while interpreting the http response.

@frankdejonge
Copy link
Member

@sergeh if it works now and nothing is broken, could you close the issue? Otherwise, feel free to ask more questions.

@sergeh
Copy link
Author

sergeh commented Aug 19, 2015

@frankdejonge just did more tests on production and it seems to work fine, thanks!

@sergeh sergeh closed this as completed Aug 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants