亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 PDF 文件上傳到 Parse 服務器?

如何將 PDF 文件上傳到 Parse 服務器?

千巷貓影 2023-09-13 17:58:06
我需要幫助在 android Studio 中使用 JAVA 將 pdf 文件上傳到解析服務器。我嘗試使用以下代碼:private ParseObject uploadPDFToParse(File PDFFile, ParseObject po, String columnName){    if(PDFFile != null){        Log.d("EB", "PDFFile is not NULL: " + PDFFile.toString());        ByteArrayOutputStream out = new ByteArrayOutputStream();        BufferedInputStream in = null;        try {            in = new BufferedInputStream(new FileInputStream(PDFFile));        } catch (FileNotFoundException e) {            e.printStackTrace();        }        int read;        byte[] buff = new byte[1024];        try {            while ((read = in.read(buff)) > 0)            {                out.write(buff, 0, read);            }        } catch (IOException e) {            e.printStackTrace();        }        try {            out.flush();        } catch (IOException e) {            e.printStackTrace();        }        byte[] pdfBytes = out.toByteArray();        // Create the ParseFile        ParseFile file = new ParseFile(PDFFile.getName() , pdfBytes);        po.put(columnName, file);        // Upload the file into Parse Cloud        file.saveInBackground();        po.saveInBackground();    }    return po;}
查看完整描述

1 回答

?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

嘗試以下代碼并讓我知道:


private ParseObject uploadPDFToParse(File PDFFile, ParseObject po, String columnName){


    if(PDFFile != null){

        Log.d("EB", "PDFFile is not NULL: " + PDFFile.toString());

        int size = (int) file.length();

        byte[] pdfBytes = new byte[size];


        try {

            BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));

            buf.read(pdfBytes, 0, pdfBytes.length);

            buf.close();

        } catch (FileNotFoundException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }

        // Create the ParseFile

        ParseFile file = new ParseFile(PDFFile.getName() , pdfBytes);

        po.put(columnName, file);


        // Upload the file into Parse Cloud

        file.save();

        po.saveInBackground();

    }

    return po;

}


查看完整回答
反對 回復 2023-09-13
  • 1 回答
  • 0 關注
  • 91 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號