@@ -161,6 +161,24 @@ type Client interface {
161161 // to the given file path. A single request should not upload more than 150
162162 // MB of file contents.
163163 UploadSessionFinish (arg * UploadSessionFinishArg , content io.Reader ) (res * FileMetadata , err error )
164+ // UploadSessionFinishBatch : This route helps you commit many files at once
165+ // into a user's Dropbox. Use `uploadSessionStart` and
166+ // `uploadSessionAppendV2` to upload file contents. We recommend uploading
167+ // many files in parallel to increase throughput. Once the file contents
168+ // have been uploaded, rather than calling `uploadSessionFinish`, use this
169+ // route to finish all your upload sessions in a single request.
170+ // `UploadSessionStartArg.close` or `UploadSessionAppendArg.close` needs to
171+ // be true for last `uploadSessionStart` or `uploadSessionAppendV2` call.
172+ // This route will return job_id immediately and do the async commit job in
173+ // background. We have another route `uploadSessionFinishBatchCheck` to
174+ // check the job status. For the same account, this route should be executed
175+ // serially. That means you should not start next job before current job
176+ // finishes. Also we only allow up to 1000 entries in a single request
177+ UploadSessionFinishBatch (arg * UploadSessionFinishBatchArg ) (res * async.LaunchEmptyResult , err error )
178+ // UploadSessionFinishBatchCheck : Returns the status of an asynchronous job
179+ // for `uploadSessionFinishBatch`. If success, it returns list of result for
180+ // each entry
181+ UploadSessionFinishBatchCheck (arg * async.PollArg ) (res * UploadSessionFinishBatchJobStatus , err error )
164182 // UploadSessionStart : Upload sessions allow you to upload a single file
165183 // using multiple requests. This call starts a new upload session with the
166184 // given data. You can then use `uploadSessionAppendV2` to add more data
@@ -2714,6 +2732,160 @@ func (dbx *apiImpl) UploadSessionFinish(arg *UploadSessionFinishArg, content io.
27142732 return
27152733}
27162734
2735+ //UploadSessionFinishBatchAPIError is an error-wrapper for the upload_session/finish_batch route
2736+ type UploadSessionFinishBatchAPIError struct {
2737+ dropbox.APIError
2738+ EndpointError struct {} `json:"error"`
2739+ }
2740+
2741+ func (dbx * apiImpl ) UploadSessionFinishBatch (arg * UploadSessionFinishBatchArg ) (res * async.LaunchEmptyResult , err error ) {
2742+ cli := dbx .Client
2743+
2744+ if dbx .Config .Verbose {
2745+ log .Printf ("arg: %v" , arg )
2746+ }
2747+ b , err := json .Marshal (arg )
2748+ if err != nil {
2749+ return
2750+ }
2751+
2752+ req , err := http .NewRequest ("POST" , (* dropbox .Context )(dbx ).GenerateURL ("api" , "files" , "upload_session/finish_batch" ), bytes .NewReader (b ))
2753+ if err != nil {
2754+ return
2755+ }
2756+
2757+ req .Header .Set ("Content-Type" , "application/json" )
2758+ if dbx .Config .AsMemberID != "" {
2759+ req .Header .Set ("Dropbox-API-Select-User" , dbx .Config .AsMemberID )
2760+ }
2761+ if dbx .Config .Verbose {
2762+ log .Printf ("req: %v" , req )
2763+ }
2764+ resp , err := cli .Do (req )
2765+ if dbx .Config .Verbose {
2766+ log .Printf ("resp: %v" , resp )
2767+ }
2768+ if err != nil {
2769+ return
2770+ }
2771+
2772+ defer resp .Body .Close ()
2773+ body , err := ioutil .ReadAll (resp .Body )
2774+ if err != nil {
2775+ return
2776+ }
2777+
2778+ if dbx .Config .Verbose {
2779+ log .Printf ("body: %s" , body )
2780+ }
2781+ if resp .StatusCode != 200 {
2782+ if resp .StatusCode == 409 {
2783+ var apiError UploadSessionFinishBatchAPIError
2784+ err = json .Unmarshal (body , & apiError )
2785+ if err != nil {
2786+ return
2787+ }
2788+ err = apiError
2789+ return
2790+ }
2791+ var apiError dropbox.APIError
2792+ if resp .StatusCode == 400 {
2793+ apiError .ErrorSummary = string (body )
2794+ err = apiError
2795+ return
2796+ }
2797+ err = json .Unmarshal (body , & apiError )
2798+ if err != nil {
2799+ return
2800+ }
2801+ err = apiError
2802+ return
2803+ }
2804+ err = json .Unmarshal (body , & res )
2805+ if err != nil {
2806+ return
2807+ }
2808+
2809+ return
2810+ }
2811+
2812+ //UploadSessionFinishBatchCheckAPIError is an error-wrapper for the upload_session/finish_batch/check route
2813+ type UploadSessionFinishBatchCheckAPIError struct {
2814+ dropbox.APIError
2815+ EndpointError * async.PollError `json:"error"`
2816+ }
2817+
2818+ func (dbx * apiImpl ) UploadSessionFinishBatchCheck (arg * async.PollArg ) (res * UploadSessionFinishBatchJobStatus , err error ) {
2819+ cli := dbx .Client
2820+
2821+ if dbx .Config .Verbose {
2822+ log .Printf ("arg: %v" , arg )
2823+ }
2824+ b , err := json .Marshal (arg )
2825+ if err != nil {
2826+ return
2827+ }
2828+
2829+ req , err := http .NewRequest ("POST" , (* dropbox .Context )(dbx ).GenerateURL ("api" , "files" , "upload_session/finish_batch/check" ), bytes .NewReader (b ))
2830+ if err != nil {
2831+ return
2832+ }
2833+
2834+ req .Header .Set ("Content-Type" , "application/json" )
2835+ if dbx .Config .AsMemberID != "" {
2836+ req .Header .Set ("Dropbox-API-Select-User" , dbx .Config .AsMemberID )
2837+ }
2838+ if dbx .Config .Verbose {
2839+ log .Printf ("req: %v" , req )
2840+ }
2841+ resp , err := cli .Do (req )
2842+ if dbx .Config .Verbose {
2843+ log .Printf ("resp: %v" , resp )
2844+ }
2845+ if err != nil {
2846+ return
2847+ }
2848+
2849+ defer resp .Body .Close ()
2850+ body , err := ioutil .ReadAll (resp .Body )
2851+ if err != nil {
2852+ return
2853+ }
2854+
2855+ if dbx .Config .Verbose {
2856+ log .Printf ("body: %s" , body )
2857+ }
2858+ if resp .StatusCode != 200 {
2859+ if resp .StatusCode == 409 {
2860+ var apiError UploadSessionFinishBatchCheckAPIError
2861+ err = json .Unmarshal (body , & apiError )
2862+ if err != nil {
2863+ return
2864+ }
2865+ err = apiError
2866+ return
2867+ }
2868+ var apiError dropbox.APIError
2869+ if resp .StatusCode == 400 {
2870+ apiError .ErrorSummary = string (body )
2871+ err = apiError
2872+ return
2873+ }
2874+ err = json .Unmarshal (body , & apiError )
2875+ if err != nil {
2876+ return
2877+ }
2878+ err = apiError
2879+ return
2880+ }
2881+ err = json .Unmarshal (body , & res )
2882+ if err != nil {
2883+ return
2884+ }
2885+
2886+ return
2887+ }
2888+
27172889//UploadSessionStartAPIError is an error-wrapper for the upload_session/start route
27182890type UploadSessionStartAPIError struct {
27192891 dropbox.APIError
0 commit comments