• 大小: 1.79MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-25
  • 语言: Java
  • 标签: 阿里云  saas  网盘  oss  

资源简介

基于阿里云的java网盘 OSS网盘实现_3分.zip 阿里云 saas 对象存储服务 网盘 oss

资源截图

代码片段和文件信息

package javacloud;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.*;

import javax.swing.JProgressBar;
import javax.swing.ProgressMonitor;
import javax.swing.ProgressMonitorInputStream;

import com.aliyun.openservices.ClientConfiguration;
import com.aliyun.openservices.ClientException;
import com.aliyun.openservices.oss.*;
import com.aliyun.openservices.oss.model.*;

public class CloudManage {
private static final String ACCESS_ID = “CiLeKzg6iBlPHG7U“;
    private static final String ACCESS_KEY = “ChozGIJkN1Tsco6H3WscZGWxym7hl8“;
    private static final String OSS_ENDPOINT = “http://oss.aliyuncs.com/“;
    static OSSClient client;
    static String bucketName;
    ClientConfiguration config;
    static String Downfilepath;
    CloudManage(String bucketname)
    {
     config = new ClientConfiguration();
     client = new OSSClient(OSS_ENDPOINT ACCESS_ID ACCESS_KEY config);
     bucketName=bucketname;
     Downfilepath=new String();
        ensureBucket(client bucketName);
    }

    public static void initCloudManage(String bucketname)
    {
     new CloudManage(bucketname);
    }
    
    // 如果Bucket不存在,则创建它。
    private static void ensureBucket(OSSClient client String bucketName)
            throws OSSException ClientException{
        if (client.isBucketExist(bucketName)){
            return;
       }
        //创建bucket
        client.createBucket(bucketName);
    }
    // 上传文件
    public static PutobjectResult uploadFile(String key String filenameJProgressBar progressbar)
            throws OSSException ClientException FileNotFoundException {
        File file = new File(filename);
        objectmetadata objectmeta = new objectmetadata();
        objectmeta.setContentLength(file.length());
        InputStream input = new FileInputStream(file);
        PutobjectResult result=client.putobject(bucketName key input objectmeta);
progressbar.setValue(1);
        return result;
    }
    public static void uploadnullFile(String key String filename) throws FileNotFoundException
    {
        File file = new File(filename);
        objectmetadata objectmeta = new objectmetadata();
        objectmeta.setContentLength(file.length());
        InputStream input = new FileInputStream(file);
        PutobjectResult result=client.putobject(bucketName key input objectmeta);
        file.delete();
    }
    //上传大文件
public static CompleteMultipartUploadResult uploadbigFile(String key String filenameJProgressBar progressbar)
throws Exception {
InitiateMultipartUploadRequest initiateMultipartUploadRequest = new InitiateMultipartUploadRequest(
bucketName key);
InitiateMultipartUploadResult initiateMultipartUploadResult = client
.initiateMultipartUpload(initiateMultipartUploadRequest);
// 设置每块为 5M
final int partSize = 1024 * 1024 * 5;
File partFile = new Fil

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-02-22 21:43  javacloud\
     文件         991  2014-02-14 21:11  javacloud\.classpath
     文件         385  2014-02-10 17:32  javacloud\.project
     目录           0  2014-02-22 21:43  javacloud\.settings\
     文件         598  2014-02-10 17:32  javacloud\.settings\org.eclipse.jdt.core.prefs
     目录           0  2014-02-18 09:08  javacloud\bin\
     目录           0  2014-02-22 21:43  javacloud\bin\javacloud\
     文件        6822  2014-02-17 22:02  javacloud\bin\javacloud\CloudManage.class
     文件        1872  2014-02-17 22:02  javacloud\bin\javacloud\DatabaseManage.class
     文件         819  2014-02-17 22:02  javacloud\bin\javacloud\DownloadThread.class
     文件        3867  2014-02-17 22:02  javacloud\bin\javacloud\Filemanage.class
     文件        2197  2014-02-17 22:02  javacloud\bin\javacloud\loginframe$loginaction.class
     文件         763  2014-02-17 22:02  javacloud\bin\javacloud\loginframe$RegisterAction.class
     文件        2191  2014-02-17 22:02  javacloud\bin\javacloud\loginframe.class
     文件         690  2014-02-17 22:02  javacloud\bin\javacloud\mainframe$ConfirmcloseAction.class
     文件        2807  2014-02-17 22:02  javacloud\bin\javacloud\mainframe$ToolAction.class
     文件        3617  2014-02-17 22:02  javacloud\bin\javacloud\mainframe.class
     文件        2962  2014-02-17 22:02  javacloud\bin\javacloud\MD5FileUtil.class
     文件        2172  2014-02-17 22:02  javacloud\bin\javacloud\MiddlePan$LabelMouseAction.class
     文件        3985  2014-02-17 22:02  javacloud\bin\javacloud\MiddlePan.class
     文件        1860  2014-02-17 22:02  javacloud\bin\javacloud\MyRenderer.class
     文件         939  2014-02-17 22:02  javacloud\bin\javacloud\MyTree$TreeAction.class
     文件        3237  2014-02-17 22:02  javacloud\bin\javacloud\MyTree$TreeMouseAction.class
     文件        6264  2014-02-17 22:02  javacloud\bin\javacloud\MyTree.class
     文件        2510  2014-02-17 22:02  javacloud\bin\javacloud\Popupmenu$PopupMouseaction.class
     文件        1323  2014-02-17 22:02  javacloud\bin\javacloud\Popupmenu.class
     文件        1978  2014-02-17 22:02  javacloud\bin\javacloud\registerDialog$ConfacountAction.class
     文件        1110  2014-02-17 22:02  javacloud\bin\javacloud\registerDialog$ConfpasswardAction.class
     文件        2742  2014-02-17 22:02  javacloud\bin\javacloud\registerDialog$RegisAction.class
     文件        2926  2014-02-17 22:02  javacloud\bin\javacloud\registerDialog.class
     文件         601  2014-02-17 22:02  javacloud\bin\javacloud\test.class
............此处省略31个文件信息

评论

共有 条评论