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

use POST for file download to avoid url length limits #6957

Merged
merged 2 commits into from
Jun 5, 2020

Conversation

qqmyers
Copy link
Member

@qqmyers qqmyers commented Jun 3, 2020

What this PR does / why we need it: uses POST for file download requests, avoiding problems with limits on the url length for requests for large numbers of files

Which issue(s) this PR closes:

Closes #6943

Special notes for your reviewer: We've used this on QDR since last May, but I just tried to compare with that fork to pull things over - haven't tested this commit.

Suggestions on how to test this: Nominally, if any download works, this is working. To verify that it's better than the prior code, you'll need to have enough files to have caused trouble. That was 1061 in the issue but I'd suggest a larger number for a test or make sure your test DB uses ids with the same number of digits because the issue is line length and ids in production will be longer than on a new test machine starting with id 1.

Does this PR introduce a user interface change? If mockups are available, please link/include them here: No

Is there a release notes update needed for this change?: No

Additional documentation:

@coveralls
Copy link

coveralls commented Jun 3, 2020

Coverage Status

Coverage decreased (-0.05%) to 19.585% when pulling 9fd7f23 on QualitativeDataRepository:IQSS/6943 into 66ed398 on IQSS:develop.

@djbrooke djbrooke assigned qqmyers and unassigned qqmyers Jun 3, 2020
@djbrooke
Copy link
Contributor

djbrooke commented Jun 3, 2020

Thanks @qqmyers we'll take a look. As you mentioned, those failing tests are failing on develop, so makes sense they are failing here as well.

@pdurbin pdurbin self-assigned this Jun 3, 2020
Copy link
Member

@pdurbin pdurbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments about docs and error handling. I deployed the code and it seemed to work fine on two files.

@Produces({ "application/zip" })
public Response postDownloadDatafiles(String fileIds, @QueryParam("gbrecs") boolean gbrecs, @QueryParam("key") String apiTokenParam, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) throws WebApplicationException {

fileIds = fileIds.substring(8); // String "fileIds=" from the front
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was playing with this using curl and got a NullPointerException when fileIds was null (and a 500 error). Some error checking would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is error checking. I just defeated it by taking a substring of null before the error check is done in downloadDataFiles() :-) Will fix.

// TODO: Rather than only supporting looking up files by their database IDs,
// consider supporting persistent identifiers.
@Path("datafiles")
@POST
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this API should be documented along side the other ones in the Data Access API page of the API Guide. I can imagine the same error that was reported in #6943 could easily happen to API users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added - feel free to change.

} catch (IOException ex) {
logger.info("Failed to issue a redirect to file download url.");
}
PrimeFaces.current().executeScript("downloadFiles('"+fileDownloadUrl + "','"+ multiFileString+"');");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a comment but I assume that PrimeFaces is being used here because there's no JSF standard way (FacesContext way) to execute a script.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain but this is done elsewhere and I assume PF needed this method for some reason. I didn't find anything else with a quick web check.

@pdurbin pdurbin assigned qqmyers and unassigned pdurbin Jun 3, 2020

Verified

This commit was signed with the committer’s verified signature.
targos Michaël Zasso
Copy link
Member

@pdurbin pdurbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't run the code this time but I'm happy to see the fixes in 9fd7f23. Thanks, @qqmyers . Off to QA.

@kcondon kcondon self-assigned this Jun 5, 2020
@kcondon kcondon merged commit 97e7a60 into IQSS:develop Jun 5, 2020
@djbrooke djbrooke added this to the Dataverse 5 milestone Jun 8, 2020
@pdurbin pdurbin mentioned this pull request Jun 17, 2020
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

Successfully merging this pull request may close these issues.

414 error when trying to download ~1000 files in a dataset
5 participants