2

I am trying to create an app to upload/download files to Ubuntu One, using the cloud API. Now I am at the point of implementing the upload part of the app, and I have this problem with my test case:

All files under 16303 bytes are uploaded with no problem whatsoever.

All files above 16303 bytes systematically fail to upload, with a 500 status code being returned.

I spent hours searching the web for a similar problem, to no avail.

I am using Go language, and here is the call to Ubuntu One REST API (error handling and housekeeping code removed for conciseness):

// 'n' is an object which describes the file to upload (path, size, etc.)
file, _ := os.Open(localTargetDir + n.Path)
apiUrl, _ := url.Parse("https://files.one.ubuntu.com/content" + remoteTargetDir + n.Path)
// Following line returns a pointer to a Request object with the "Authorization" 
// fields in the header all properly set
request, _ := ubuntuoneGetSignedRequest("PUT", apiUrl.String(), file)
request.Header.Add("Content-Length", fmt.Sprintf("%d", n.Size))
request.Header.Add("Content-Type", "application/octet-stream")
response, _ := http.DefaultClient.Do(request)
if response.StatusCode >= 300 {
    return errors.New(fmt.Sprintf("Error (status=%d) creating remote file: %s", response.StatusCode, n.Path))
}
// ...

As said, a file size of 16303-16304 bytes is the pivot point where the upload will begin to fail systematically. I have no idea where the problem lies.

0

1 Answer 1

1

Finally found the problem. It's a Go language thing, not a Ubuntu One thing.

Apparently, the field request.ContentLength needs to be properly set:

request.Header.Add("Content-Type", "application/octet-stream")
request.ContentLength = n.Size
response, _ := http.DefaultClient.Do(request)

It might appears obvious in retrospect (not really since it was working fine for files smaller than 16304...), but I haven't seen this documented in the Go doc.

Hopefully, this will be useful to someone at some point experiencing a similar problem.

Not the answer you're looking for? Browse other questions tagged .