public final class AVFile
extends java.lang.Object
AVFile is a local representation of a file that is saved to the AVOSCloud cloud.
The workflow is to construct a AVFile with data and optionally a filename. Then save it and set it as a field on a AVObject.
Example:AVFile file = new AVFile("hello".getBytes()); file.save(); AVObject object = new AVObject("TestObject"); object.put("file", file); object.save();
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
AVFILE_ENDPOINT |
static java.lang.String |
DEFAULTMIMETYPE |
构造器和说明 |
---|
AVFile() |
AVFile(byte[] data)
已过时。
|
AVFile(java.lang.String name,
byte[] data)
Creates a new file from a byte array and a name.
|
AVFile(java.lang.String name,
java.lang.String url,
java.util.Map<java.lang.String,java.lang.Object> metaData)
创建一个基于网络文件的AVFile对象
|
限定符和类型 | 方法和说明 |
---|---|
java.lang.Object |
addMetaData(java.lang.String key,
java.lang.Object val)
Added meta data to file.
|
void |
cancel()
Cancels the current network request and callbacks whether it's uploading or fetching data from
the server.
|
static java.lang.String |
className() |
static void |
clearAllCachedFiles()
clear all cached files
|
void |
clearCachedFile()
clear cached file for this file.
|
static void |
clearCacheMoreThanDays(int days)
clear cached files which created before x days.
|
void |
clearMetaData()
Clear file metadata.
|
void |
delete() |
void |
deleteEventually() |
void |
deleteEventually(DeleteCallback callback) |
void |
deleteInBackground() |
void |
deleteInBackground(DeleteCallback callback) |
AVACL |
getACL()
获取AVFile的ACL
|
java.lang.String |
getBucket() |
byte[] |
getData()
已过时。
|
void |
getDataInBackground(GetDataCallback dataCallback)
Gets the data for this object in a background thread.
|
void |
getDataInBackground(GetDataCallback dataCallback,
ProgressCallback progressCallback)
Gets the data for this object in a background thread. progressCallback is guaranteed to be
called with 100 before dataCallback is called.
|
java.io.InputStream |
getDataStream()
Synchronously gets the data input stream for this object.
|
void |
getDataStreamInBackground(GetDataStreamCallback callback)
Gets the data input stream for this object in a background thread.
|
void |
getDataStreamInBackground(GetDataStreamCallback callback,
ProgressCallback progressCallback)
Gets the data input stream for this object in a background thread. progressCallback is guaranteed to be
called with 100 before dataStreamCallback is called.
|
java.util.HashMap<java.lang.String,java.lang.Object> |
getMetaData()
Returns the file's metadata map.
|
java.lang.Object |
getMetaData(java.lang.String key)
Returns the metadata value by key.
|
static java.lang.String |
getMimeType(java.lang.String url)
已过时。
replaced by
AVUtils#getMimeTypeFromLocalFile(String) or
AVUtils#getMimeTypeFromUrl(String) |
java.lang.String |
getName()
The filename.
|
java.lang.String |
getObjectId()
Returns the file object Id.
|
java.lang.String |
getOriginalName() |
java.lang.String |
getOwnerObjectId()
Returns the file's owner
|
int |
getSize()
Returns the file size in bytes.
|
java.lang.String |
getThumbnailUrl(boolean scaleToFit,
int width,
int height)
Returns a thumbnail image url using QiNiu endpoints.
|
java.lang.String |
getThumbnailUrl(boolean scaleToFit,
int width,
int height,
int quality,
java.lang.String fmt)
返回缩略图URl 这个服务仅仅适用于保存在Qiniu的图片
|
Uploader |
getUploader(SaveCallback saveCallback,
ProgressCallback progressCallback) |
java.lang.String |
getUrl()
This returns the url of the file.
|
boolean |
isDataAvailable()
已过时。
|
boolean |
isDirty()
Whether the file still needs to be saved.
|
static AVFile |
parseFileWithAbsoluteLocalPath(java.lang.String name,
java.lang.String absoluteLocalFilePath)
已过时。
Please use #
withAbsoluteLocalPath(String, String) |
static AVFile |
parseFileWithAVObject(AVObject obj)
已过时。
Please use #
withAVObject(AVObject) |
static AVFile |
parseFileWithFile(java.lang.String name,
java.io.File file)
已过时。
Please use #
withFile(String, File) |
static AVFile |
parseFileWithObjectId(java.lang.String objectId)
已过时。
Please use #
withObjectId(String) |
static void |
parseFileWithObjectIdInBackground(java.lang.String objectId,
GetFileCallback<AVFile> cb)
已过时。
|
java.lang.Object |
removeMetaData(java.lang.String key)
Remove file meta data.
|
void |
save()
Saves the file to the AVOSCloud cloud synchronously.
|
void |
saveInBackground()
Saves the file to the AVOSCloud cloud in a background thread.
|
void |
saveInBackground(SaveCallback callback)
Saves the file to the AVOSCloud cloud in a background thread.
|
void |
saveInBackground(SaveCallback saveCallback,
ProgressCallback progressCallback)
Saves the file to the AVOSCloud cloud in a background thread. progressCallback is guaranteed to
be called with 100 before saveCallback is called.
|
void |
setACL(AVACL acl) |
void |
setBucket(java.lang.String bucket) |
void |
setName(java.lang.String name) |
void |
setObjectId(java.lang.String objectId)
Set the file objectId.
|
static void |
setUploadHeader(java.lang.String key,
java.lang.String value)
set http header while uploading.
|
void |
setUrl(java.lang.String url) |
static AVFile |
withAbsoluteLocalPath(java.lang.String name,
java.lang.String absoluteLocalFilePath)
Creates a new file from local file path.
|
static AVFile |
withAVObject(AVObject obj)
Construct a AVFile from AVObject.
|
static AVFile |
withFile(java.lang.String name,
java.io.File file)
Creates a new file from java.io.File object.
|
static AVFile |
withObjectId(java.lang.String objectId)
Retrieve a AVFile object by object id from AVOSCloud.If the file is not found,it will throw
java.io.FileNotFoundException.
|
static void |
withObjectIdInBackground(java.lang.String objectId,
GetFileCallback<AVFile> cb)
Retrieve a AVFile object by object id from AVOSCloud in background.If the file is not found,it
will call the callback with java.io.FileNotFoundException.
|
public static java.lang.String DEFAULTMIMETYPE
public static final java.lang.String AVFILE_ENDPOINT
public AVFile()
@Deprecated public AVFile(byte[] data)
data
- The file's data. 请注明文件名public AVFile(java.lang.String name, java.lang.String url, java.util.Map<java.lang.String,java.lang.Object> metaData)
name
- 文件名url
- 网络文件的urlmetaData
- 网络文件的元信息,可以为空public AVFile(java.lang.String name, byte[] data)
name
- The file's name, ideally with extension.data
- The file's datapublic static void setUploadHeader(java.lang.String key, java.lang.String value)
key
- - header namevalue
- - header valuepublic java.lang.String getObjectId()
public void setObjectId(java.lang.String objectId)
objectId
- file object id.@Deprecated public static void parseFileWithObjectIdInBackground(java.lang.String objectId, GetFileCallback<AVFile> cb)
withObjectIdInBackground(String, GetFileCallback)
objectId
- The file object id.cb
- The GetFileCallback instance.public static void withObjectIdInBackground(java.lang.String objectId, GetFileCallback<AVFile> cb)
objectId
- The file object id.cb
- The GetFileCallback instance.@Deprecated public static AVFile parseFileWithObjectId(java.lang.String objectId) throws AVException, java.io.FileNotFoundException
withObjectId(String)
objectId
- AVException
- ,FileNotFoundExceptionjava.io.FileNotFoundException
public static AVFile withObjectId(java.lang.String objectId) throws AVException, java.io.FileNotFoundException
objectId
- AVException
- ,FileNotFoundExceptionjava.io.FileNotFoundException
@Deprecated public static AVFile parseFileWithAVObject(AVObject obj)
withAVObject(AVObject)
obj
- The AVObject.public static AVFile withAVObject(AVObject obj)
obj
- The object.@Deprecated public static AVFile parseFileWithAbsoluteLocalPath(java.lang.String name, java.lang.String absoluteLocalFilePath) throws java.lang.Exception
withAbsoluteLocalPath(String, String)
name
- The file's name, ideally with extension.absoluteLocalFilePath
- The file's absolute path.java.lang.Exception
public static AVFile withAbsoluteLocalPath(java.lang.String name, java.lang.String absoluteLocalFilePath) throws java.io.FileNotFoundException
name
- The file's name, ideally with extension.absoluteLocalFilePath
- The file's absolute path.java.io.FileNotFoundException
@Deprecated public static AVFile parseFileWithFile(java.lang.String name, java.io.File file) throws java.io.FileNotFoundException
withFile(String, File)
name
- The file's name, ideally with extension.file
- The file object.java.io.FileNotFoundException
java.io.IOException
public static AVFile withFile(java.lang.String name, java.io.File file) throws java.io.FileNotFoundException
name
- The file's name, ideally with extension.file
- The file object.java.io.FileNotFoundException
java.io.IOException
public java.util.HashMap<java.lang.String,java.lang.Object> getMetaData()
public java.lang.Object addMetaData(java.lang.String key, java.lang.Object val)
key
- The meta data's key.val
- The meta data's value.public java.lang.Object getMetaData(java.lang.String key)
key
- The metadata keypublic int getSize()
public java.lang.String getOwnerObjectId()
public java.lang.Object removeMetaData(java.lang.String key)
key
- The meta data's keypublic void clearMetaData()
public java.lang.String getName()
public java.lang.String getOriginalName()
public void setName(java.lang.String name)
name
- public static java.lang.String getMimeType(java.lang.String url)
AVUtils#getMimeTypeFromLocalFile(String)
or
AVUtils#getMimeTypeFromUrl(String)
url
- public boolean isDirty()
@Deprecated public boolean isDataAvailable()
public java.lang.String getUrl()
public java.lang.String getThumbnailUrl(boolean scaleToFit, int width, int height)
scaleToFit
- width
- height
- getThumbnailUrl(boolean, int, int, int, String)
public java.lang.String getThumbnailUrl(boolean scaleToFit, int width, int height, int quality, java.lang.String fmt)
scaleToFit
- Whether to scale the imagewidth
- The thumbnail image's widthheight
- The thumbnail image'heightquality
- The thumbnail image quality in 1 - 100.fmt
- The thumbnail image format such as 'jpg','gif','png','tif' etc.public void setUrl(java.lang.String url)
public void save() throws AVException
AVException
public void saveInBackground(SaveCallback saveCallback, ProgressCallback progressCallback)
saveCallback
- A SaveCallback that gets called when the save completes.progressCallback
- A ProgressCallback that is called periodically with progress updates.public void saveInBackground(SaveCallback callback)
callback
- A SaveCallback that gets called when the save completes.public void saveInBackground()
@Deprecated public byte[] getData() throws AVException
getDataInBackground(GetDataCallback)
instead
unless you're already in a background thread.
Notice: for large file(above 20MB), it is dangerous to read whole data once time,
instead of, you should use getDataStream()
to read the content.AVException
public java.io.InputStream getDataStream() throws AVException
getDataStreamInBackground(GetDataStreamCallback)
instead
unless you're already in a background thread.
Notice: You need to close the input stream after reading content from it.AVException
public void getDataInBackground(GetDataCallback dataCallback, ProgressCallback progressCallback)
getDataStreamInBackground(GetDataStreamCallback, ProgressCallback)
to read the content.dataCallback
- A GetDataCallback that is called when the get completes.progressCallback
- A ProgressCallback that is called periodically with progress updates.public void getDataInBackground(GetDataCallback dataCallback)
getDataStreamInBackground(GetDataStreamCallback)
to read the content.dataCallback
- A GetDataCallback that is called when the get completes.public void getDataStreamInBackground(GetDataStreamCallback callback)
callback
- A GetDataStreamCallback that is called when the get completes.public void getDataStreamInBackground(GetDataStreamCallback callback, ProgressCallback progressCallback)
callback
- A GetDataStreamCallback that is called when the get completes.progressCallback
- A ProgressCallback that is called periodically with progress updates.public void cancel()
public void delete() throws AVException
AVException
AVObject.delete()
public void deleteEventually()
AVObject.deleteEventually()
public void deleteEventually(DeleteCallback callback)
callback
- AVObject.deleteEventually(DeleteCallback callback);
public void deleteInBackground()
AVObject.deleteInBackground();
public void deleteInBackground(DeleteCallback callback)
callback
- AVObject.deleteInBackground(DeleteCallback callback);
public static java.lang.String className()
public Uploader getUploader(SaveCallback saveCallback, ProgressCallback progressCallback)
public java.lang.String getBucket()
public void setBucket(java.lang.String bucket)
public AVACL getACL()
public void setACL(AVACL acl)
public void clearCachedFile()
public static void clearAllCachedFiles()
public static void clearCacheMoreThanDays(int days)
days
- - peroid from now.Copyright © 2013 AVOS Systems Inc. All Rights Reserved.