Skip to content

Commit d76407b

Browse files
authored
fix(dropbox): incorrect path error during upload (#1052)
* Fix incorrect path error during upload on Dropbox * Add RootNamespaceId to the config for direct modification * Refactor Dropbox header logic: extract JSON marshaling into helper method * Fix Dropbox: replace marshalToJSONString with utils.Json.MarshalToString
1 parent 5de6b66 commit d76407b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

drivers/dropbox/meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Addition struct {
1313
ClientSecret string `json:"client_secret" required:"false" help:"Keep it empty if you don't have one"`
1414
AccessToken string
1515
RefreshToken string `json:"refresh_token" required:"true"`
16-
RootNamespaceId string
16+
RootNamespaceId string `json:"RootNamespaceId" required:"false"`
1717
}
1818

1919
var config = driver.Config{

drivers/dropbox/util.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ func (d *Dropbox) finishUploadSession(ctx context.Context, toPath string, offset
175175
}
176176
req.Header.Set("Content-Type", "application/octet-stream")
177177
req.Header.Set("Authorization", "Bearer "+d.AccessToken)
178+
if d.RootNamespaceId != "" {
179+
apiPathRootJson, err := d.buildPathRootHeader()
180+
if err != nil {
181+
return err
182+
}
183+
req.Header.Set("Dropbox-API-Path-Root", apiPathRootJson)
184+
}
178185

179186
uploadFinishArgs := UploadFinishArgs{
180187
Commit: struct {
@@ -219,6 +226,13 @@ func (d *Dropbox) startUploadSession(ctx context.Context) (string, error) {
219226
}
220227
req.Header.Set("Content-Type", "application/octet-stream")
221228
req.Header.Set("Authorization", "Bearer "+d.AccessToken)
229+
if d.RootNamespaceId != "" {
230+
apiPathRootJson, err := d.buildPathRootHeader()
231+
if err != nil {
232+
return "", err
233+
}
234+
req.Header.Set("Dropbox-API-Path-Root", apiPathRootJson)
235+
}
222236
req.Header.Set("Dropbox-API-Arg", "{\"close\":false}")
223237

224238
res, err := base.HttpClient.Do(req)
@@ -233,3 +247,11 @@ func (d *Dropbox) startUploadSession(ctx context.Context) (string, error) {
233247
_ = res.Body.Close()
234248
return sessionId, nil
235249
}
250+
251+
func (d *Dropbox) buildPathRootHeader() (string, error) {
252+
return utils.Json.MarshalToString(map[string]interface{}{
253+
".tag": "root",
254+
"root": d.RootNamespaceId,
255+
})
256+
}
257+

0 commit comments

Comments
 (0)