-
Notifications
You must be signed in to change notification settings - Fork 53
Shared Link for a docx/xlsx file cannot be downloaded #105
Comments
Related: OneDrive/onedrive-explorer-android#75 The format of URLs that OneDrive returns are not always in a pattern that work for the Android Download manager, this 'limited' behavior is documented degree here http://www.digiblog.de/2011/04/android-and-the-download-file-headers/ In order to avoid this issue you can use a getContent() request to download the file bytes and put them where desired, see how the OneDrive Explorer Android does this in its DisplayItem.java@91. InputStream in = null;
try {
in = oneDriveClient()
.getDrive()
.getItems(mId)
.getContent()
.buildRequest()
.get();
} catch (...) {
// Handle errors
}
// Use `in` stream to place the file contents where desired. |
Hi again, |
Thanks for the clarification, you can do this with a little bit of legwork Once you've created a link, you'll have a webUrl in the response:
If you just query this link, you'll get a 301 message which should redirect you to a url like so:
If you replace the For some additional background on what you can do with sharing links see https://dev.onedrive.com/shares/shares.htm |
Hi @peternied , thanks for the help, but I'm having some issues with this:
application.getOneDriveClient()
.getDrive()
.getItems(item.id)
.getCreateLink(items[selection.get()].toString())
.buildRequest()
.create(new DefaultCallback<Permission>(getActivity()) {
@Override
public void success(final Permission permission) {
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(permission.link.webUrl);
Log.d("OneDriveSDK", "> link.WebUrl: " + permission.link.webUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
int responseCode = connection.getResponseCode();
InputStream inputStream = connection.getInputStream();
URL newURL = connection.getURL();
Log.d("OneDriveSDK", "> responseCode: " + responseCode);
Log.d("OneDriveSDK", "> newURL: " + newURL);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
|
I have the same problem. The docx, pptx, xlsx... documents can't be downloaded directly when i get the public link. |
@daboxu It looks like we need a solution for downloading from sharing links via ODB, can you provide instructions for that? |
one possible approach is using our /shares API for ODB. The link "permission.link.webUrl" actually could be encode into a share key by: shareId = "u!" + urlfriendly(base64encode(permission.link.webUrl)) after we got the shareId, you can compose a request to /shares API to get the content: BaseApplication app = ((BaseApplication) activity.getApplication());
app.getOneDriveClient().getExecutors().performOnBackground(new Runnable() {
@Override
public void run() {
IOneDriveClient client = ((BaseApplication) activity.getApplication()).getOneDriveClient();
String request = client.getShare(shareId).getRequestUrlWithAdditionalSegment("/root/content");
// remove "/me" part of the serviceRoot because /shares does not exist under /me
if (((BaseApplication) activity.getApplication()).getOneDriveClient().getAuthenticator().getAccountInfo().getServiceRoot().endsWith("/me")) {
request = request.replaceFirst("/me", "");
}
// append access token
request += ("?access_token=" + client.getAuthenticator().getAccountInfo().getAccessToken());
try {
URL contentUrl = new URL(request);
HttpURLConnection connection = (HttpURLConnection) contentUrl.openConnection();
int responseCode = connection.getResponseCode();
InputStream inputStream = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = br.readLine()) != null) {
Log.d("Custom", line);
}
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}); while this approache you need not only the link, but also a valid access token which I believe you will have if you already allow user grant it to you |
hi @thekindJose @ginesguirpa, have you found the way for the problem? |
Hi @daboxu. No, I haven't found how to do what I need. |
hi @thekindJose , sorry misunderstood your scenario. Unfortunately right now we don't support downloading office documents via a sharing link but thanks for the suggestion and it indeed is a good feature. Please go to http://onedrive.uservoice.com/ to post it so that other can vote on it as well. |
Hi, I'm using the onedrive api explorer to get familiar with how to use it and I've run into the following problem:
When I create a link to share a docx or an xlsx file, and send the link to someone, it directly opens the browser to view the file. But when I create a link for a png file, the link shared allows the person who receives the link to download it.
If I try to download the link generated for a docx/xlsx file within a sample app which uses the android download manager there is an error which does not let me to download it.
Any clue about what to do to be able to download the docx/xlsx file using the shared link?
Thanks!
The text was updated successfully, but these errors were encountered: