我试图通过 restlet 接收文件,但只获得完整的 MULTIPART_FORM_DATA。如何提取我的特定文件?
我发现了一些代码块,但它们的类型不可用... RESTlet:如何处理多部分/表单数据请求?
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1000240);
// 2/ Create a new file upload handler
RestletFileUpload upload = new RestletFileUpload(factory);
我当前的代码:
@Put
public void handleUpload(Representation entity) {
if (entity !=null) {
if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
Request restletRequest = getRequest();
Response restletResponse = getResponse();
HttpServletRequest servletRequest = ServletUtils.getRequest(restletRequest);
HttpServletResponse servletResponse = ServletUtils.getResponse(restletResponse);
try {
Upload2(restletRequest, entity);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public void Upload2(Request req, Representation entity) throws IOException
{
...
GcsOutputChannel outputChannel = gcsService.createOrReplace(fileName, GcsFileOptions.getDefaultInstance());
ObjectOutputStream oout = new ObjectOutputStream(Channels.newOutputStream(outputChannel));
copy(entity.getStream(), oout);
oout.close();
用这种方法存储后,我有类似的东西,我只想存储名为“图片”的内容:
��z------WebKitFormBoundarysOvzWKPqyqW7DiTu
Content-Disposition: form-data; name="picture"; filename="_MG_4369.jpg"
Content-Type: image/jpeg
����*ExifII*
据我所知,还不支持多部分表单数据的解析?但是必须有解决方案通过restlet发送文件
我通过邮递员为 chrome 尝试了休息电话。仅在多部分上支持文件。是否可以将图像作为原始文本发送?