安卓平台
我的全局应用程序配置如下
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, Application Id, Client key);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
我保存文件如下
ParseObject pIssue = new ParseObject(Constants.STUDENT_CLASS);
pIssue.put(Constants.STUDENT_TITLE, mTitleView.getText().toString());
if(mCurrentPhotoPath != null){
byte[] imgData = photoHelper.convertFileToByteArray(mCurrentPhotoPath);
ParseFile pFile = new ParseFile("heya",imgData);
pIssue.put(Constants.STUDENT_MEDIA_FILES, pFile);
}
pIssue.saveEventually();
convertFileToByteArray 方法看起来像这样
public byte[] convertFileToByteArray(String filePath) {
byte[] byteArray = null;
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
byteArray = out.toByteArray();
return byteArray;
}
我在一个单独的线程中检索了图像文件,如下所示
f = new File(filename); // this file is valid
url=parseFile.getUrl(); // this is the url mentioned below
try {
Bitmap bitmap=null;
URL imageUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream(); // code breaks and throws exception here
OutputStream os = new FileOutputStream(f);
Utils.CopyStream(is, os);
os.close();
conn.disconnect();
bitmap = decodeFile(f);
return bitmap;
} catch (Exception ex){
ex.printStackTrace();
return null;
}
问题是在检索时出现以下异常 java.io.FileNotFoundException: http: //files.parse.com/e13c8e5c-9234-4160-9d63-b802696f9251/heya
在这一步代码中断 - InputStream is=conn.getInputStream();
当我使用 parseFile.getData() 时,我得到“无法解码为位图,异常”可能是因为检索到的数据不是图像。
当我从浏览器点击上述网址时,我得到
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>.........</RequestId>
<HostId>
...................
</HostId>
</Error>
表中的所有文件都会出现此错误
请帮助我哪里错了........ :(