Buenas noches a todos, tengo el siguiente inconveniente. Tengo que subir un archivo por pedazos a través de un servicio expuesto en rest. He logrado subir el archivo completo mediante este codigo:
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);
WebResource web = client.resource("https://storage.cloudlayer.com/v1/files/");
File archivo = new File("ruta.txt")
FormDataMultiPart part = new FormDataMultiPart();
FileDataBodyPart file = new FileDataBodyPart();
file.setName("filename");
file.setFileEntity(archivo,MediaType.APPLICATION_O CTET_STREAM_TYPE);
part.bodyPart(file);
part.field("output","json");
String response = web.type(MediaType.MULTIPART_FORM_DATA_TYPE).post( String.class, part);
pero no logro enviar el mismo parte por parte. A continuación anexo lo que son las instrucciones de conexión con este api para ver si me pueden ayudar a interpretarlo y lograr el cometido.
How to Upload a File One Part At a Time To transfer a file one piece at a time, a file create then a series of file updates are
performed then the new file is unlocked. Each piece of the file can be of any size. The first piece is transferred as part of the create,
which returns the file OID and the lock ID. All subsequent pieces are transferred as updates to the new file, with each subsequent
piece modifying the file OID returned from the create and passing in the lock ID returned from the create. In each update, the
offset of the new piece from the beginning of the file must be specified. Offsets are specified using the HTTP “Content-Range”
header field. At the end, the lock ID returned by the create is unlocked using the lock command.
An example might be helpful. To upload a file called “example” in 100 byte pieces, an HTTP post is made to “/v1/files/” with
the body containing the first 100 bytes (offsets 0-99) of the file. It returns a file OID and a lock ID, in this case the file OID is
“57CC826C-4B70-4A96-B665-08A953573C70” and the lock ID is “66DB917B-5C7F-5BA5-C756-17B862664B8F.” The bytes 100-199 of
the file are transferred by doing a POST to “/v1/files/57CC826C-4B70-4A96-B665-08A953573C70” making sure that there is an HTTP
header “Content-Range: 100-199” and another one with “X-Mezeo-Lock: 66DB917B-5C7F-5BA5-C756-17B862664B8F” and including
the 100 bytes starting at offset 100 in the file. The third block, 200-299 is transferred by doing a post to “/v1/files/57CC826C-
4B70-4A96-B665-08A953573C70” making sure that there is an HTTP header “Content-Range: 200-299” and another one with
“X-Mezeo-Lock: 66DB917B-5C7F-5BA5-C756-17B862664B8F” and including the 100 bytes starting at offset 200 in the file. This
continues until the last block has been transferred.
La solución completa para el hilo: aquí.
At the end, a POST to “/v1/files/57CC826C-4B70-4A96-B665-08A953573C70/lock” is performed, specifying an “action” parameter
with the value “unlock” and a “lockid” parameter with the value “66DB917B-5C7F-5BA5-C756-17B862664B8F.” This unlocks the file.
When uploading a file a piece at a time, performance can be improved by delaying finalization until the end of the transfer. This is
done by including an “X-Mezeo-Suppress-Finalize” HTTP header field.Messages that do not contain an “X-Mezeo-Suppress-Finalize”
will finalize the file after every transfer. Therefore, the last transfer would not include the “X-Mezeo-Suppress-Finalize” HTTP
header so that the finalization steps can be completed.
Agradeceria Enormemente su ayuda, de antemano muchas gracias



Citar
Marcadores