2012年11月22日 星期四

Parse.com 超簡單 架Mobile Android Server教學 4.Files

Files 檔案處理


The ParseFile 

ParseFile可以讓你存各種資料格式
byte[] data = "Working at Parse is great!".getBytes();
ParseFile file = new ParseFile("resume.txt", data);
如果存的是png檔,記得要followPNG結尾,Parse比較好優化。
一樣用saveInBackground()等..
file.saveInBackground();
一樣可以將Parsefile 塞入 ParseObject。
ParseObject jobApplication = new ParseObject("JobApplication");
jobApplication.put("applicantName", "Joe Smith");
jobApplication.put("applicantResumeFile", file);
jobApplication.saveInBackground();
取回檔案。
ParseFile applicantResume = (ParseFile)anotherApplication.get("applicantResumeFile");
applicantResume.getDataInBackground(new GetDataCallback() {
  public void done(byte[] data, ParseException e) {
    if (e == null) {
      // data has the bytes for the resume
    } else {
      // something went wrong
    }
  }
});


Progress

可以做到設定 percent,但目前依舊bug中....
byte[] data = "Working at Parse is great!".getBytes();
ParseFile file = new ParseFile("resume.txt", data);
file.saveInBackground(new SaveCallback() {
  public void done(ParseException e) {
    // Handle success or failure here ...
  }
}, new ProgressCallback() {
  public void done(Integer percentDone) {
    // Update your progress spinner here. percentDone will be between 0 and 100.
  }
});

沒有留言:

張貼留言