1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
public static int doUpload(BufferedImage image, BufferedImage miniature, String filename, String url, String clientId, String albumId) throws Exception
{
PostMethod filePost = new PostMethod(url);
byte[] dataImage = ProcessImage.toJpegByte(image);
ByteArrayPartSource byteArrayImage = new ByteArrayPartSource(filename, dataImage);
byte[] dataImageMiniature = ProcessImage.toJpegByte(miniature);
ByteArrayPartSource byteArrayImageMini = new ByteArrayPartSource(PREFIX_MINIPICTURE + filename, dataImageMiniature);
// Les informations à envoyer
Part[] parts = {
new StringPart(CLIENT_ID, clientId),
new StringPart(ALBUM_ID, albumId),
new FilePart(byteArrayImageMini.getFileName(), byteArrayImageMini),
new FilePart(byteArrayImage.getFileName(), byteArrayImage)
};
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
// Recuperation du statut
int statut = client.executeMethod(filePost);
// Liberation de la connection
filePost.releaseConnection();
return statut;
} |
Partager