Skip to content

Commit

Permalink
Encode filename in B2 download URL
Browse files Browse the repository at this point in the history
Previously this caused downloads of file names with % to fail.
  • Loading branch information
gaul committed Apr 8, 2017
1 parent 0d3b88b commit c94dfa2
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package org.jclouds.b2.blobstore;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -480,7 +482,12 @@ private MutableBlobMetadata toBlobMetadata(String container, B2Object b2Object)
contentMetadata.setContentType(b2Object.contentType());
metadata.setContentMetadata(contentMetadata);
metadata.setUserMetadata(b2Object.fileInfo());
metadata.setPublicUri(URI.create(auth.get().downloadUrl() + "/file/" + container + "/" + b2Object.fileName()));
try {
metadata.setPublicUri(URI.create(auth.get().downloadUrl() + "/file/" + container + "/" +
URLEncoder.encode(b2Object.fileName(), "UTF-8")));
} catch (UnsupportedEncodingException uee) {
throw new RuntimeException(uee);
}
return metadata;
}
}

0 comments on commit c94dfa2

Please sign in to comment.