webservice定义: <xsd:element name="attachmentPartBytes" type="xsd:base64Binary"/>
private void attachmentPartUpload(File file, String fileName,
String businessId, String attrId,String fileSecurityVal) throws Exception {
byte[] bytes = null;
long maxSize = 1024 * 1024 * 2;
long length = file.length();
InputStream is = new FileInputStream(file);
long offset = 0;
long endIndex = 0;
int i = 0;
while (endIndex < length) {
offset = i * maxSize;
endIndex = (i + 1) * maxSize;
if (endIndex > length) {
endIndex = length;
}
int byteLen = (int) (endIndex - offset);
bytes = new byte[byteLen];
is.read(bytes, 0, byteLen);
AttachmentPartUploadRequest request = new AttachmentPartUploadRequest();
AttachmentPart attachmentPart = new AttachmentPart();
attachmentPart.setAttachmentName(fileName);
attachmentPart.setBusinessId(businessId);
attachmentPart.setAttrId(attrId);
attachmentPart.setAttachmentPartBytes(bytes);
attachmentPart.setOffset(offset);
attachmentPart.setIsLastPart(endIndex < length ? 0 : 1); // endIndex < length 代表上传未结束
attachmentPart.setFileSecurityVal(fileSecurityVal);
request.setAttachmentPart(attachmentPart);
attachmentService.attachmentPartUpload(request);
i++;
}
}
attachmentPartUpload