整合阿里云OSS文件上传2

SDK下载地址http://download.csdn.net/detail/jf_2012/9385901    

/**sunjunfeng

     * 引用上面一个方法(适配文件上传OSS服务器需要)
     * 上传文件处理
     * @param html页面input标签的name 属性值 $upload_input_name
     */
    public function uploadFileNew($upload_input_name='upload'){
    //status:100=>ERROR || status:0 YES
    if($_FILES[$upload_input_name]['error'] == 4)return array('status'=>100,'msg'=>'没有文件被上传!');
   
    $upload = new uploadfilenew();
    $info = $upload->RepostNew();
    if (!empty($info)){
    $return = $info;
    $return['status'] = 1;
    }else {
    $return = $info;
    $return['status'] = 100;
    }
    return $return;
    }
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以通过以下步骤来实现Spring Boot与阿里云OSS整合: 1. 首先,将阿里云OSS的Java SDK添加到你的项目依赖中。你可以在Maven或Gradle中添加如下依赖: ```xml <dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> <version>3.13.0</version> </dependency> ``` 2. 在Spring Boot的配置文件中,配置阿里云OSS的相关信息,如accessKeyId、accessKeySecret、endpoint等。你可以将这些信息配置在`application.properties`或`application.yaml`文件中,例如: ```yaml spring: oss: access-key-id: your-access-key-id access-key-secret: your-access-key-secret endpoint: your-oss-endpoint ``` 3. 创建一个OSS客户端的Bean,用于访问OSS服务。可以使用`@Configuration`注解创建一个配置类,例如: ```java import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class OSSConfig { @Value("${spring.oss.access-key-id}") private String accessKeyId; @Value("${spring.oss.access-key-secret}") private String accessKeySecret; @Bean public OSS ossClient() { return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); } } ``` 4. 在需要使用OSS的地方注入`OSS`对象,并调用相应的方法进行操作。例如,上传文件到OSS: ```java import com.aliyun.oss.OSS; import com.aliyun.oss.model.ObjectMetadata; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class OSSService { @Autowired private OSS ossClient; public void uploadFile(String bucketName, String objectName, String filePath) { ossClient.putObject(bucketName, objectName, new File(filePath)); } } ``` 这样,你就完成了Spring Boot与阿里云OSS整合。记得替换示例代码中的相应信息,以便与你的阿里云账号匹配。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值