Skip to content

Commit

Permalink
Chunked upload working now
Browse files Browse the repository at this point in the history
  • Loading branch information
rootik committed Aug 25, 2016
1 parent b724e2d commit 96b59be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Before you can use this tool, create an application in the [Microsoft Azure Mana
9. Submit form
10. Now open your new application and select Configure tab
11. Change "Reply URL" field to https://onedrive.live.com/about/business/
12. Add an application key, press Save and copy the generated Secret
12. Add an application key. Select 1 year key, 2 year key will not work. Press Save and copy the generated Secret
13. Also copy your "Client ID"
14. In a "Permissions to other applications" press "Add application"
15. Select "Office 365 SharePoint Online" and "Windows Azure Active Directory"
Expand Down
17 changes: 7 additions & 10 deletions onedriveb-base
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
api_auth_url="https://login.microsoftonline.com/common/oauth2/token"
api_base_url="https://isdukraine-my.sharepoint.com/_api/v2.0/"
api_discovery_url="https://api.office.com/discovery/v2.0/me/services"
api_discovery_id="https://api.office.com/discovery/"
get_json_value="cut -d= -f2-"
Expand Down Expand Up @@ -65,7 +64,7 @@ function curl_find_subfolder() {
fi

local folder_name=$(urlencode "$2")
local url="${api_base_url}/drive/${folder_id}:/${folder_name}?access_token=${api_access_token}"
local url="${api_uri}/drive/${folder_id}:/${folder_name}?access_token=${api_access_token}"

curl \
${curl_opts} \
Expand All @@ -80,10 +79,10 @@ function curl_create_folder() {
local url

if [ -z "$1" ]; then
url="${api_base_url}/drive/${api_root_folder}/children?access_token=${api_access_token}"
url="${api_uri}/drive/${api_root_folder}/children?access_token=${api_access_token}"
else
local folder_id=$(urlencode "$1")
url="${api_base_url}/drive/items/${folder_id}/children?access_token=${api_access_token}"
url="${api_uri}/drive/items/${folder_id}/children?access_token=${api_access_token}"
fi

curl \
Expand All @@ -107,7 +106,7 @@ function curl_get_access_token() {
--header "Content-Type: application/x-www-form-urlencoded" \
--data "client_id=${api_client_id}" \
--data "client_secret=${api_client_secret}" \
--data "redirect_uri=${api_reply_url}" \
--data "redirect_uri=${api_redirect_uri}" \
--data "refresh_token=$1" \
--data "grant_type=refresh_token" \
--data "resource=$2" \
Expand Down Expand Up @@ -202,7 +201,7 @@ function curl_upload_chunk() {
--header "Content-Length: ${current_range_length}" \
--header "Content-Range: bytes ${current_range_start}-${current_range_end}/${filesize}" \
--data-binary @- \
"${1}?access_token=${api_access_token}"
"${1}&access_token=${api_access_token}"
}


Expand Down Expand Up @@ -277,8 +276,6 @@ function onedrive_request_upload_session() {
exit_on_error

upload_url=$(echo "${api_parsed_json_result}" | grep "uploadUrl" | ${get_json_value})
# Remove access_token from upload_url
upload_url=$(echo "${upload_url/?access_token=*/}")

if [ "${upload_url}" == "" ]; then
error "An error has occurred while requesting an upload session: ${api_parsed_json_result}"
Expand Down Expand Up @@ -356,7 +353,7 @@ function onedrive_upload_file_simple() {
}

function onedrive_upload_file_chunked() {
curl_discover_uri 'get_api'
curl_discover_uri 'get_api'
api_access_token=$(onedrive_acquire_access_token ${api_resource_id})
exit_on_error

Expand Down Expand Up @@ -388,7 +385,7 @@ function onedrive_upload_file_chunked() {
fi

status_code=$(curl_upload_chunk "${upload_url}" "${current_chunk}")

debug "Status code: ${status_code}"
retry_count=$((retry_count+1))
done

Expand Down
6 changes: 3 additions & 3 deletions onedriveb.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export refresh_token_file="${script_base_folder}/.refresh_token"

# Authentication config
export api_client_id="b66d1076-4c04-4a33-8bb2-2578c4891886"
export api_client_secret="x73LaIRCimtjiiw/DuHA000Ozwcf4nz1Ovcpi0xUCHI="
export api_redirect_uri="https://onedrive.live.com/about/en-US/business/"
export api_client_id=""
export api_client_secret=""
export api_redirect_uri="https://onedrive.live.com/about/business/"
# Permission to request on first authorization: One of ["onedrive.readwrite", "onedrive.appfolder"]
export api_permissions="onedrive.readwrite"

Expand Down

0 comments on commit 96b59be

Please sign in to comment.