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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 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)

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

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

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

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

Method to use PHP and Qiniu cloud storage interface to realize feature extraction and similarity matching of images Method to use PHP and Qiniu cloud storage interface to realize feature extraction and similarity matching of images Jul 06, 2023 am 11:49 AM

Method of using PHP and Qiniu cloud storage interface to realize image feature extraction and similarity matching Introduction: In today's Internet era, the use of image data is becoming more and more widespread. How to effectively manage and retrieve large amounts of image data has become an important issue. question. Image feature extraction and similarity matching are one of the core technologies to achieve efficient image retrieval. This article will introduce how to use PHP and Qiniu cloud storage interface to implement image feature extraction and similarity matching. 1. Introduction to Qiniu Cloud Storage Qiniu Cloud Storage is a well-known cloud storage service in China.

How to use PHP to delete Base64 format images from Qiniu Cloud Storage? How to use PHP to delete Base64 format images from Qiniu Cloud Storage? Sep 05, 2023 pm 05:28 PM

How to use PHP to delete Base64 format images from Qiniu Cloud Storage? With the development of the Internet, data storage and processing have become more and more convenient. The emergence of cloud storage services provides developers with a more convenient way to store and manage data. As a well-known cloud storage service provider, Qiniu Cloud Storage provides rich functions and good performance, and is favored by the majority of developers. When using Qiniu Cloud Storage, sometimes we need to delete images that have been uploaded to cloud storage on the server side. If the picture is in Bas

See all articles