将对象(jpg)序列化到内部存储
我正在尝试从 Amazon S3 下载一组 .jpg 并将它们存储到内部存储(这样恶意用户就无法复制它们)。我已经走到这一步了,但现在我陷入了困境。我发现了多个涉及位图或数组的问题,但没有发现有关存储图像然后稍后访问它的问题。有人知道我从这里去哪里吗?
String itemName = iconNames.getString(iconNames.getColumnIndexOrThrow(DbAdapter.KEY_ICON));
itemName = itemName + ".jpg";
GetObjectRequest getObject = new GetObjectRequest(bucket, itemName);
S3Object icon = mS3Client.getObject(getObject);
InputStream input = icon.getObjectContent();
我在开发指南中查看了这里,它给出了以下代码 http://developer.android.com/guide/topics/data /data-storage.html#filesInternal
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
但这是用于存储字符串,而不是图像......
I am trying to download a set of .jpg's from Amazon S3 and store them to the internal storage (so they can't be copied by a malicious user). I have gotten this far but now I am stuck. I have found multiple questions that deal with bitmaps or arrays but nothing about storing an image and then accessing it later. Anyone know where I go from here?
String itemName = iconNames.getString(iconNames.getColumnIndexOrThrow(DbAdapter.KEY_ICON));
itemName = itemName + ".jpg";
GetObjectRequest getObject = new GetObjectRequest(bucket, itemName);
S3Object icon = mS3Client.getObject(getObject);
InputStream input = icon.getObjectContent();
I have looked here in the dev guide and it gives the following code
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
But this is for storing a string, not an image...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将
InputStream
复制到OutputStream
。像这样的事情:You have to copy
InputStream
toOutputStream
. Something like this:你可以做类似下面的事情。
You could do something like the following.