cancel
Showing results for 
Search instead for 
Did you mean: 

Objective C batchUploadFiles gives error: "missing required field 'session_id'" or "Garbage at end."

SOLVED
517 Views
10 Comments
0 Kudos
Highlighted

Objective C batchUploadFiles gives error: "missing required field 'session_id'" or "Garbage at end."

Hi,

 

I am getting the error 

 

 

DropboxBadInputError[{
ErrorContent = "Error in call to API function \"files/upload_session/finish_batch\": request body: entries.cursor: missing required field 'session_id'";
RequestId = 0af1f37eb6e9ebc3e7ea0695db52c593;
StatusCode = 400;
UserMessage = nil;
}];

 

 

 

And

 

 

"DropboxClientError[{\n    NSError = \"Error Domain=NSCocoaErrorDomain Code=3840 \\\"Garbage at end.\\\" UserInfo={NSDebugDescription=Garbage at end.}\";

 

Search for the 

 

 

[[DBClientsManager authorizedClient].filesRoutes
                                batchUploadFiles:uploadFilesUrlsToCommitInfo
                                queue:nil

 

inside the code. 

 

I posted the entire method because I was worried that some part of the method maybe affecting the the batch upload. 

 

The begin upload method works like this 

 

1) it finds the photos that are present in the dropbox,

2) it compares it with photos present in the app,

3) then it deletes photos and other files that are in dropbox that are not present in the app or need to be deleted

4) Finally through batchupload it uploads all the photos that are not present into dropbox.

 

I really need help to fix this , been searching through the internet and trying different approaches but can't find an answer. Hopping someone can help

 

 Update:(easier to implement code for anyone who wants to help)

Here is the entire code

https://github.com/git-tyl/WineCellarProblemCode/blob/master/problemUploadingDropboxCode.m

 

1 Accepted solution

Accepted Solutions
Solution
Dropboxer

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &am

Thanks! This is very helpful. I'm able to reproduce this now. We're looking into it.

We have a rough idea of what's occurring, though not exactly why it's occurring yet. One thing that may be relevant though is that for some calls, you're using `setProgressBlock` and checking `if (totalBytesUploaded == totalBytesExpectedToUploaded` to see if the operation is complete. You should always use the response block (e.g., `setResponseBlock` for most calls, or passed as a parameter for `batchUploadFiles`) to know when the operation completed and then carry on with your next steps.

Please try making that change and let me know if it does or doesn't help. Thanks!
10 Replies
Dropboxer

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &qu

Thanks for the report! It looks like there's a good amount of code here, and I won't be able to run it, since it contains things from your app, like `WCPURLHelper`.

Can you isolate just the portion(s) of Dropbox related code that results in these issues so we can look into it? We'd first need to be able to reproduce the issue to investigate it.

Also, note that the latest version of the Objective-C SDK is 3.2.0. If you're not already on that version, please try upgrading to it first.

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &qu

Thanks Greg for helping.

 

I've edited the code to be easily tested, so you can lift it and put it in your app. All you need to do is:

 

1) In the documents directory of the iphone app make a photo and call it MainPhoto.db //yes change the extension to .db, this is to repiclicate the db file i transfer in the app

2) Next in the documents directory make a folder called photos, add about 20 or so pngs// you can just use cmd-d to duplicate one photo many times

3)Once you do that you should be able to run the method, this method will have "Garbage at end of file" then further use of this method will cause session_id errors

 

In addition, I've updated the dropbox api to 3.2 in the app, but the problems still occurs.

 

Here is the entire code

https://github.com/git-tyl/WineCellarProblemCode/blob/master/problemUploadingDropboxCode.m

Dropboxer

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &am

Thanks! That's very helpful. We'll look into it.
Dropboxer

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &am

I just followed your instructions and was able to run your supplied code, but I didn't get either of these error messages.

There must be some other factor, so can you perhaps plug it in to a sample project that reproduces the issues for you and share that?

Also, in case it matters, what version of Xcode are you using?

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &am

Ok i'll test it on a sample project.

Have you tried multiple times , it sometimes will succeed but most of the time it will not.

Xcode Version 8.3.3 (8E3004b)

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &am

Ok I've created an entirely new project but I still get the problem. I've publish this sample project in github and I've published the sample photos that I use to test the problem so you can put the sample photos into the document's folder of the app.

https://github.com/git-tyl/DropboxTestProblem
Solution
Dropboxer

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &am

Thanks! This is very helpful. I'm able to reproduce this now. We're looking into it.

We have a rough idea of what's occurring, though not exactly why it's occurring yet. One thing that may be relevant though is that for some calls, you're using `setProgressBlock` and checking `if (totalBytesUploaded == totalBytesExpectedToUploaded` to see if the operation is complete. You should always use the response block (e.g., `setResponseBlock` for most calls, or passed as a parameter for `batchUploadFiles`) to know when the operation completed and then carry on with your next steps.

Please try making that change and let me know if it does or doesn't help. Thanks!

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &am

You were right, it was the completetion code being put into the progressblock. Its now working. Many thanks.

 

I've updated the new code

 

https://github.com/git-tyl/DropboxTestProblem

Level 2

Re: Objective C batchUploadFiles gives error: "missing required field 'session_id'" or &am

I'm actually receiving the same error, but I've got the correct code in the response block (I think).  It doesn't seem to happen on the first batch upload call during a run, but the second upload attempt seems to fail pretty consistently.  Here's my code, if it helps.

 

[self.fileRoutes batchUploadFiles:filesToUpload
                                queue:self.fileUploadQueue
                        progressBlock:^(int64_t uploaded, int64_t uploadedTotal, int64_t expectedToUploadTotal) {
                            if (fileSize.intValue > 0) {
                                float progress = (float) uploadedTotal / fileSize.longLongValue;
                                photo.uploadProgress = progress;
                            }
                        }
                        responseBlock:^(NSDictionary<NSURL *, DBFILESUploadSessionFinishBatchResultEntry *> *fileUrlsToBatchResultEntries,
                                DBASYNCPollError *finishBatchRouteError, DBRequestError *finishBatchRequestError,
                                NSDictionary<NSURL *, DBRequestError *> *fileUrlsToRequestErrors) {
                            DBFILESUploadSessionFinishBatchResultEntry *result = fileUrlsToBatchResultEntries[srcPath];
                            if (result.isSuccess) {
                                [self uploadedFile:destPath from:srcPath.absoluteString metadata:result.success];
                            } else {
                                NSMutableDictionary *userInfo = [[NSMutableDictionary new] autorelease];
                                userInfo[@"path"] = srcPath.absoluteString;

                                if (fileUrlsToRequestErrors) {
                                    NSMutableDictionary<NSURL *, NSString *> *errors = [[NSMutableDictionary new] autorelease];
                                    for (NSURL *key in fileUrlsToRequestErrors.allKeys) {
                                        errors[key] = fileUrlsToRequestErrors[key].errorContent;
                                    }
                                    userInfo[@"fileErrors"] = errors;
                                }

                                if (finishBatchRouteError) {
                                    userInfo[@"routeError"] = finishBatchRouteError.description;
                                }

                                if (finishBatchRequestError) {
                                    userInfo[@"requestError"] = finishBatchRequestError.errorContent;
                                }

                                // TODO Handle conflicts here
                                if (result.failure.isPath){
                                    if (result.failure.path.isConflict) {
                                        // TODO Handle This
                                        DLog(@"Conflicting filename: %@, %@", photo.filename, result.failure.path.conflict)
                                    }
                                }

                                NSError *err = [NSError errorWithDomain:@"my.app" code:0 userInfo:userInfo];
                                [self uploadFileFailedWithError:err];
                            }
                        }];