サーバにzipファイルをアップロードした後、解凍できないという問題に直面しました。 私は次のエンドポイントの例でDropwizardフレームワークに基づいてREST APIがあります。Dropwizardフレームワーク経由でアップロードした後、Zipファイルを解凍することはできません
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/zip")
public class ImportResource {
@POST
public Response fileService(@FormDataParam("fileData") InputStream fileDataInputStream,
@FormDataParam("fileData") FormDataContentDisposition fileDataDetail) {
File newFile = new File("/Users/alexx/Documents/"+ fileDataDetail.getFileName());
try {
final OutputStream out = new FileOutputStream(newFile);
ByteStreams.copy(fileDataInputStream, out);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Response.ok().build();
}
// save uploaded file to new location
private void writeToFile(InputStream uploadedInputStream, String uploadedFileLocation) throws IOException {
int read;
final int BUFFER_LENGTH = 1024;
final byte[] buffer = new byte[BUFFER_LENGTH];
OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
while ((read = uploadedInputStream.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
out.flush();
out.close();
}
もアプリケーション・クラスで、私は適切なクラス提供:zipファイルをアップロードした後
....
bootstrap.addBundle(new MultiPartBundle());
....
environment.jersey().register(MultiPartFeature.class);
を、それはアップロードのように見えますが、それを次のメッセージが受信されました:
(エラー1 - 操作は許可されていません)。
テキストファイルと画像ファイルが正しくアップロードされて開きます。
何もスキップしましたか?追加のパラメータを追加するか、どこかに設定する必要がありますか? ありがとうございます!