Send the file in chunks with metadata

I'm writing a web application and the application OS X, which will upload files to the server.

The web application uses FlowJS to handle sending files to the server. Along with each request it sends the chunk was number, block size, total file size, file name, etc. It's great, because behind the scenes I load the data into the S3, and I use this information to determine when the file is complete. Moreover, since the data comes in pieces, I do not need to store the entire file into memory on my server.

For OS X with an objective c I plan to use AFNetworking. I tried to use a multi-boot:

-(void)uploadFileWithUrl:(NSURL*)filePath { AFHTTPRequestOperationManager*manager = [AFHTTPRequestOperationManager manager]; [manager POST:@"http://www.example.com/files/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileURL:filePath name:@"blob" error:nil]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; } 

but it's just trying to send the entire file into a single request, which is unacceptable, as the large queries will be no memory.

I would like to know if something like FlowJS there for the C object, or if there is some way to include this information in AFNetworking for each call.

+6
source share
1 answer

I do not think you can do it automatically very easily. (And if someone knows how to do it, I would like to know the answer.)

Multipart does not help, because it structures the content, but does not transmit. Think of it as a paragraph in a text document: they give the text structure, but it is still the same file.

This leads to the real problem: you want to have a fixed-size pieces and sent a piece after treatment (loaded at S3), then the next fragment, and so on. As a customer knows that the first piece is treated? HTTP does not work the way you can send new data when the first one is received by the server. You are sending the following snippet, when the first leaves (on the way). I'm not sure whether the guarantee AFNetworking request for the next part after sending the first part ... Maybe she wants to collect small pieces.

Why do not you do this, S3:

Initiates a download request with the identifier as a response. Then send the piece, using the ID loaded. If this is done, the server responds, and the next part will be sent. Do you have a handshake.

-1
source

All Articles