Home Backend Development PHP Tutorial 怎么解决七牛云图片url上传的问题

怎么解决七牛云图片url上传的问题

Jun 06, 2016 pm 08:31 PM
Qiniu Cloud Storage

怎么解决七牛云图片url上传的问题

解决七牛云图片url上传问题的方法:

七牛云图片url上传

项目中用到要把非自家源的图片转换为自家源的图片的问题,想通过七牛云解决,对着七牛云开发文档看了很久也没啥眉目,

最后因为公司与七牛有合作,所以找到七牛的大佬才得以解决,下面是解决方案:

首先找一个项目引入七牛sdk 链接:https://developer.qiniu.com/kodo/sdk/1239/java

然后  将下面代码复制到 main方法中,修改 ACCESS_KEY   SECRET_KEY   bucketname  为自己的 

即可运行,控制台输出的就是图片名称(这名称就是key的值  我是自定义的当前时间加上三位随机数,前面是你的域名)

//参考api文档https://developer.qiniu.com/kodo/api/4097/asynch-fetch
//设置好账号的ACCESS_KEY和SECRET_KEY
String  oldUrl ="http://r3.ykimg.com/050C0000525611A967583907F10CA01F";
String[]  newUrl =oldUrl.split(";");
System.out.println(newUrl.length);
for (int i=0;i
Random  random =new Random();
    StringACCESS_KEY="your accessKey";
    StringSECRET_KEY="your secretKey";
    //要上传的空间
    String bucketname ="your bucketName";
    Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
    // 构造post请求body
    Gson gson =new Gson();
    Map m =new HashMap();
    m.put("url", newUrl[i]);
    m.put("bucket", bucketname);
    m.put("key", +System.currentTimeMillis()+random.nextInt(100)+".jpg");
    System.out.println("https://域名/"+m.get("key"));
    StringparaR= gson.toJson(m);
    byte[] bodyByte = paraR.getBytes();
    String url ="http://api-z0.qiniu.com/sisyphus/fetch";
    String accessToken = (String) auth.authorizationV2(url, "POST", bodyByte, "application/json")
.get("Authorization");
    Client client =new Client();
    StringMap headers =new StringMap();
    headers.put("Authorization", accessToken);
    try {
com.qiniu.http.Response resp = client.post(url, bodyByte, headers, Client.JsonMime);
    }catch (Exception e) {
throw new Exception(e.getMessage());
    }
}
Copy after login

更多相关技术知识,请访问PHP中文网

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
How to use PHP to upload images in Base64 format to Qiniu Cloud Storage and generate thumbnails? How to use PHP to upload images in Base64 format to Qiniu Cloud Storage and generate thumbnails? Sep 05, 2023 am 08:48 AM

How to use PHP to upload images in Base64 format to Qiniu Cloud Storage and generate thumbnails? Introduction: With the development of the Internet, the application of images is becoming more and more widespread, and image processing has become a common requirement. Qiniu Cloud Storage provides convenient image storage and processing services. This article will introduce how to use PHP to upload images in Base64 format to Qiniu Cloud Storage and generate thumbnails. Step 1: Install the necessary dependencies Before starting, we need to ensure that PHP and Composer are installed on the system (

How to use PHP to download and decode images in Base64 format from Qiniu Cloud Storage? How to use PHP to download and decode images in Base64 format from Qiniu Cloud Storage? Sep 05, 2023 pm 03:22 PM

How to use PHP to download and decode images in Base64 format from Qiniu Cloud Storage? In modern Internet applications, the storage and processing of image resources are crucial. Qiniu Cloud Storage, as a stable cloud storage platform, provides users with rich image processing functions. This article will introduce how to use PHP to download and decode images in Base64 format from Qiniu Cloud Storage. 1. Create a Qiniu Cloud Storage account and obtain an API key. First, you need to register an account on the Qiniu Cloud Storage official website and successfully create a storage space. in successfully creating

Practical Guide to Connecting PHP and Qiniu Cloud Storage Interface Practical Guide to Connecting PHP and Qiniu Cloud Storage Interface Jul 05, 2023 pm 01:54 PM

Practical Guide to Interfacing PHP with Qiniu Cloud Storage Interface Introduction: Cloud storage has become one of the commonly used solutions in most website development. Qiniu Cloud Storage, as the leading domestic cloud storage service provider, is loved by many developers. This article will introduce how to use PHP to interface with Qiniu Cloud Storage, and provide relevant code examples. 1. Register a Qiniu cloud storage account and create a storage space. Before starting, we need to register a Qiniu cloud storage account and create a storage space. The registration URL is https://w

How to use PHP to convert pictures in Qiniu cloud storage to Base64 format and export it? How to use PHP to convert pictures in Qiniu cloud storage to Base64 format and export it? Sep 05, 2023 pm 04:36 PM

How to use PHP to convert pictures in Qiniu cloud storage to Base64 format and export it? In recent years, with the popularity and widespread application of cloud storage, more and more websites and applications choose to store pictures and other files in the cloud so that they can be obtained and shared anytime and anywhere. As a leading cloud service provider, Qiniu Cloud Storage is highly respected in the industry for its stability and efficiency. This article will introduce how to use PHP to convert images in Qiniu Cloud Storage to Base64 format and export them locally. First, we need to use Qiniu Cloud Storage

Method to realize image encryption and decryption through PHP and Qiniu cloud storage interface Method to realize image encryption and decryption through PHP and Qiniu cloud storage interface Jul 08, 2023 pm 08:55 PM

The method of image encryption and decryption through PHP and Qiniu cloud storage interface. With the development of the Internet, people increasingly rely on cloud storage services in their daily lives. Qiniu Cloud Storage, as one of the leading cloud storage service providers in China, provides users with stable and efficient storage services. While storing users' files, protecting the privacy and security of files has also become a focus of cloud storage service providers. This article will introduce how to implement image encryption and decryption through PHP and Qiniu cloud storage interface. 1. Introduction to Qiniu Cloud Storage Qiniu Cloud Storage

Use PHP and Qiniu cloud storage interface to realize image pornography and sensitive information detection functions Use PHP and Qiniu cloud storage interface to realize image pornography and sensitive information detection functions Jul 06, 2023 pm 03:39 PM

Use PHP and Qiniu cloud storage interface to realize the pornographic identification and sensitive information detection functions of pictures. Introduction: With the development of the Internet, pictures are disseminated more and more widely, but there are also some pictures that are pornographic or contain sensitive information. In order to filter these bad pictures, we can use the interface of Qiniu Cloud Storage and combine it with the PHP programming language to implement the pornography and sensitive information detection functions of uploaded pictures. This article will introduce how to use PHP to write code and combine it with the Qiniu cloud storage interface to implement this function. Article text: 1. Introduction to Qiniu Cloud Storage 7

How to use Qiniu Cloud Storage in ThinkPHP6 How to use Qiniu Cloud Storage in ThinkPHP6 Jun 20, 2023 pm 01:32 PM

With the continuous development and optimization of cloud computing technology, cloud storage has become the storage method chosen by more and more enterprises and individuals. Among them, Qiniu Cloud Storage is favored by the majority of users for its high reliability, high availability and high cost performance. So, how to use Qiniu Cloud Storage in ThinkPHP6? This article will introduce it to you in detail. 1. Register a Qiniu Cloud account and create a storage space. First, we need to go to the Qiniu Cloud official website to register an account. After successful registration, in the "Object Storage" page, we can create our own storage space. here

Method to realize real-time processing and quick preview of images using PHP and Qiniu cloud storage interface Method to realize real-time processing and quick preview of images using PHP and Qiniu cloud storage interface Jul 05, 2023 am 09:28 AM

Method of using PHP and Qiniu cloud storage interface to achieve real-time processing and quick preview of images Summary: This article will introduce how to use PHP and Qiniu cloud storage interface to achieve real-time processing and quick preview of images. We explain specific steps through sample code to help readers understand how to process images, generate thumbnails, and provide quick preview functions. Introduction With the rapid development of the Internet, pictures, as one of the important elements in information transmission, are widely used in various fields. In order to improve user experience, we usually need to process images, such as raw

See all articles