use of org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource in project zm-mailbox by Zimbra.
the class ZMailbox method uploadAttachment.
/**
* Uploads a byte array to <tt>FileUploadServlet</tt>.
* @return the attachment id
*/
public String uploadAttachment(String name, byte[] content, String contentType, int msTimeout) throws ServiceException {
FilePart part = new FilePart(name, new ByteArrayPartSource(name, content));
part.setContentType(contentType);
return uploadAttachments(new Part[] { part }, msTimeout);
}
use of org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource in project sling by apache.
the class HttpOsgiClient method installBundle.
@Override
public void installBundle(InputStream in, String fileName) throws OsgiClientException {
if (in == null) {
throw new IllegalArgumentException("in may not be null");
}
if (fileName == null) {
throw new IllegalArgumentException("fileName may not be null");
}
// append pseudo path after root URL to not get redirected for nothing
final PostMethod filePost = new PostMethod(repositoryInfo.appendPath("system/console/install"));
try {
// set referrer
filePost.setRequestHeader("referer", "about:blank");
List<Part> partList = new ArrayList<>();
partList.add(new StringPart("action", "install"));
partList.add(new StringPart("_noredir_", "_noredir_"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(in, baos);
PartSource partSource = new ByteArrayPartSource(fileName, baos.toByteArray());
partList.add(new FilePart("bundlefile", partSource));
partList.add(new StringPart("bundlestart", "start"));
Part[] parts = partList.toArray(new Part[partList.size()]);
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
int status = getHttpClient().executeMethod(filePost);
if (status != 200) {
throw new OsgiClientException("Method execution returned status " + status);
}
} catch (IOException e) {
throw new OsgiClientException(e);
} finally {
filePost.releaseConnection();
}
}
Aggregations