0

ブロブを正常にアップロードしているサーブレットを作成しましたが、名前なしでアップロードしていますサーブレットでアップロードされたファイルの名前を設定する方法

ここにサーブレットコードのセグメントがあります

public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {



         FileService fileService = FileServiceFactory.getFileService();

          // Create a new Blob file with mime-type "text/plain"

          String url="http://www.cbwe.gov.in/htmleditor1/pdf/sample.pdf";
          URL url1=new URL(url);
          HttpURLConnection conn=(HttpURLConnection) url1.openConnection();
          String content_type=conn.getContentType();
          InputStream stream =conn.getInputStream();
          AppEngineFile file = fileService.createNewBlobFile("application/pdf");

          file=new AppEngineFile(file.getFullPath());
         Boolean lock = true;
          FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);

          // This time we write to the channel directly
          String s1="";
          String s2="";

          byte[] bytes = IOUtils.toByteArray(stream);


          writeChannel.write(ByteBuffer.wrap(bytes));
          writeChannel.closeFinally();
4

2 に答える 2

0

あなたはあなたのURLからファイル名を得ることができます

String fileNameWithoutExtn = url.substring(0、url.lastIndexOf('。'));

次に、fileNameをパラメーターとして渡します

FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock,fileNameWithoutExtn );
于 2012-08-11T10:37:52.863 に答える
0

ファイル名を2番目のパラメータとしてに渡しますfileService.createNewBlobFile("application/pdf", "filename.pdf")

于 2012-08-11T10:22:11.050 に答える