Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.qiniu.android.storage;
  
  
  import java.io.File;

七牛文件上传管理器 一般默认可以使用这个类的方法来上传数据和文件。这个类自动检测文件的大小, 只要超过了Configuration.putThreshold
 
 public final class UploadManager {
     private final Configuration config;
     private final HttpManager httpManager;
 
     public UploadManager() {
         this(new Configuration.Builder().build());
     }
 
     public UploadManager(Configuration config) {
         this. = config;
         this. = new HttpManager(config.proxy,
                 new StatReport(), config.upIp,
                 config.connectTimeoutconfig.responseTimeoutconfig.urlConverterconfig.dns);
     }
 
     public UploadManager(Recorder recorderKeyGenerator keyGen) {
         this(new Configuration.Builder().recorder(recorderkeyGen).build());
     }
 
     public UploadManager(Recorder recorder) {
         this(recordernull);
     }
 
     private static boolean areInvalidArg(final String keybyte[] dataFile f,
                                          String tokenfinal UpCompletionHandler completionHandler) {
         if (completionHandler == null) {
             throw new IllegalArgumentException("no UpCompletionHandler");
         }
         String message = null;
         if (f == null && data == null) {
             message = "no input data";
         } else if (token == null || token.equals("")) {
             message = "no token";
         }
         if (message != null) {
             final ResponseInfo info = ResponseInfo.invalidArgument(message);
             AsyncRun.run(new Runnable() {
                 @Override
                 public void run() {
                     completionHandler.complete(keyinfonull);
                 }
             });
             return true;
         }
         return false;
     }

    
上传数据

Parameters:
data 上传的数据
key 上传数据保存的文件名
token 上传凭证
completionHandler 上传完成后续处理动作
options 上传数据的可选参数
 
     public void put(final byte[] datafinal String keyfinal String token,
                     final UpCompletionHandler completionHandlerfinal UploadOptions options) {
         if (areInvalidArg(keydatanulltokencompletionHandler)) {
             return;
         }
 
         final UpToken decodedToken = UpToken.parse(token);
         if (decodedToken == null) {
             final ResponseInfo info = ResponseInfo.invalidToken("invalid token");
             AsyncRun.run(new Runnable() {
                 @Override
                 public void run() {
                     completionHandler.complete(keyinfonull);
                 }
             });
             return;
         }
         AsyncRun.run(new Runnable() {
             @Override
             public void run() {
                 FormUploader.upload(datakeydecodedTokencompletionHandleroptions);
             }
         });
     }

    
上传文件

Parameters:
filePath 上传的文件路径
key 上传文件保存的文件名
token 上传凭证
completionHandler 上传完成的后续处理动作
options 上传数据的可选参数
    public void put(String filePathString keyString tokenUpCompletionHandler completionHandler,
                    final UploadOptions options) {
        put(new File(filePath), keytokencompletionHandleroptions);
    }

    
上传文件

Parameters:
file 上传的文件对象
key 上传文件保存的文件名
token 上传凭证
completionHandler 上传完成的后续处理动作
options 上传数据的可选参数
    public void put(File filefinal String keyString tokenfinal UpCompletionHandler completionHandler,
                    final UploadOptions options) {
        if (areInvalidArg(keynullfiletokencompletionHandler)) {
            return;
        }
        UpToken decodedToken = UpToken.parse(token);
        if (decodedToken == null) {
            final ResponseInfo info = ResponseInfo.invalidToken("invalid token");
            AsyncRun.run(new Runnable() {
                @Override
                public void run() {
                    completionHandler.complete(keyinfonull);
                }
            });
            return;
        }
        long size = file.length();
        if (size <= .) {
            FormUploader.upload(filekeydecodedTokencompletionHandleroptions);
            return;
        }
        String recorderKey = ..gen(keyfile);
        ResumeUploader uploader = new ResumeUploader(filekey,
                decodedTokencompletionHandleroptionsrecorderKey);
        AsyncRun.run(uploader);
    }
New to GrepCode? Check out our FAQ X