java上传视频到七牛云_java 上传文件到七牛云中

import com.alibaba.fastjson.JSONObject;

import com.qiniu.common.QiniuException;

import com.qiniu.common.Zone;

import com.qiniu.http.Response;

import com.qiniu.storage.Configuration;

import com.qiniu.storage.UploadManager;

import com.qiniu.util.Auth;

import org.springframework.web.multipart.MultipartFile;

import java.io.*;

import java.util.*;

public class HBYAppUtils {

//设置好账号的ACCESS_KEY和SECRET_KEY

String ACCESS_KEY = "yKD4YcCSflBrGuSzbt0nfN3b2S8DFb8SYDXBUrOZ";

//这两个登录七牛 账号里面可以找到

String SECRET_KEY = "s6R_cGNQwo-NrBy4_vennXPlhB2iOq7sUA46AV9y";

//要上传的空间

String bucketname = "ecloud-app-files";

//对应要上传到七牛上 你的那个路径(自己建文件夹 注意设置公开)

// 上传到七牛后保存的文件名

// String key = "123.html";

//上传文件的路径

// String FilePath = "C:\\Users\\沐白\\Desktop\\肺炎疫情武汉加油.html";

//本地要上传文件路径

/*

普通上传

multipartFile : form表单传过来的文件,

key: 文件名

*/

public String upload(MultipartFile multipartFile,String key) throws IOException{

// 密钥配置

Auth auth = Auth.create(ACCESS_KEY,SECRET_KEY);

//创建上传对象

Configuration configuration = new Configuration(Zone.zone0());

UploadManager uploadManager = new UploadManager(configuration);

String result = "";

FileInputStream inputStream=(FileInputStream)multipartFile.getInputStream();

byte[] uploadBytes = new byte[inputStream.available()];

ByteArrayInputStream byteInputStream=new ByteArrayInputStream(uploadBytes);

try {

//调用put方法上传

Response res = uploadManager.put(byteInputStream,key,auth.uploadToken(bucketname),null, null);

//打印返回的信息

result = key;

} catch (QiniuException e) {

e.printStackTrace();

// 请求失败时打印的异常的信息

result = "no";

}

return result;

}

//流获取输入的搜索关键字同行一行的语句

public static ArrayList isContainContent(String url, String keyWord) throws Exception{

File pathname = new File(url);

ArrayList jsonObjects = new ArrayList<>();

JSONObject jsonObject = new JSONObject();

boolean result = false;

//行读取

LineNumberReader lineReader = null;

InputStreamReader read = new InputStreamReader(new FileInputStream(pathname), "gbk");

lineReader = new LineNumberReader(read);

String readLine = null;

while((readLine =lineReader.readLine()) != null){

//判断是否包含

if(readLine.contains(keyWord)) {

// result = true;

// jsonObject.put("lineWords",readLine);

// jsonObject.put("lineNumber", lineReader.getLineNumber());

jsonObject.put("pathname",pathname);

jsonObjects.add(readLine);

}

}

//关闭流

if(lineReader != null){

try {

lineReader.close();

} catch (IOException e) {

e.printStackTrace();

// lineReader = null;

}

}

// jsonObject.put("flag", result);

return jsonObjects;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值