Skip to content
Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones

Categories

  • Automobiles (12)
    • Cars (7)
  • Blog (103)
    • Poems (2)
    • Space (2)
  • Command (2)
  • Education (2)
  • Entertainment (4)
  • Gadgets (9)
    • Phones (8)
      • Android Phones (4)
  • HTML Templates (11)
  • IT Training Institutes (1)
  • Lifestyle (4)
  • News (51)
  • Others (23)
  • Programming (296)
    • API (16)
    • CSS (83)
    • Database (4)
    • Hosting (1)
    • HTML (37)
    • JavaScript (117)
      • JQuery (27)
      • ReactJS (7)
    • PHP (116)
  • Python (3)
  • recipes (1)
  • SEE Result (1)
  • Server (3)
  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones
Close

Search

PHP

Uploading file to OBS in Huawei Cloud Services using PHP

By Admin
February 2, 2023 2 Min Read
Comments Off on Uploading file to OBS in Huawei Cloud Services using PHP

Huawei Cloud is a cloud computing platform offered by Huawei, a leading global information and communications technology (ICT) solutions provider. It provides a range of cloud services, including computing, storage, databases, network, security, artificial intelligence, and Internet of Things (IoT), among others.

Huawei Cloud enables businesses of all sizes to build, deploy, and run their applications and services in the cloud, providing the scalability, reliability, and security that organizations require. With Huawei Cloud, you can get started quickly, with no upfront investment or long-term commitment, and only pay for what you use.

Huawei Cloud aims to provide a secure and reliable cloud computing platform for customers globally, with a focus on serving the needs of the Asian market.

To upload a file to Huawei OBS (Object Storage Service), you need to perform the following steps:

Steps to Upload File to Huawei OBS (Object Storage Service)

1. Log in to the Huawei Cloud Management Console and navigate to the OBS Service page.
2. Create a bucket, which is a container for storing your data.
3. Click the bucket to open it and then select “Upload Files”.
4. Select the file you want to upload and click “Open” to start the upload process.
5. Once the upload is complete, the file will be stored in the bucket and can be accessed from there.

Note: Huawei OBS may have specific requirements for file types and sizes, so make sure to check these before uploading your files.

Here is a sample PHP code that you can use to upload a file to Huawei OBS:

Sample PHP Script to upload Files to Huawei OBS (Object Storage Service)

<?php

// replace with your OBS access key and secret key
$accessKey = "YOUR_ACCESS_KEY";
$secretKey = "YOUR_SECRET_KEY";

// replace with your OBS endpoint and bucket name
$endpoint = "https://obs.cn-north-1.myhuaweicloud.com";
$bucket = "YOUR_BUCKET_NAME";

// replace with the path to your file
$filePath = "path/to/your/file.txt";

// create a request for the PUT object operation
$url = "$endpoint/$bucket/".basename($filePath);
$contentType = mime_content_type($filePath);
$date = gmdate('D, d M Y H:i:s T');
$signature = base64_encode(hash_hmac('sha1', "PUT\n\n$contentType\n$date\n/$bucket/".basename($filePath), $secretKey, true));

// upload the file
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: $contentType",
    "Authorization: AWS $accessKey:$signature",
    "Date: $date",
]);
curl_setopt($ch, CURLOPT_INFILE, fopen($filePath, 'rb'));
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filePath));
$response = curl_exec($ch);
curl_close($ch);

// check the response for success or failure
if ($response === false) {
    die("Failed to upload file: ".curl_error($ch));
} else if (substr($response, 0, 4) != "HTTP") {
    die("Failed to upload file: Unexpected response");
} else if (strpos($response, "200 OK") === false) {
    die("Failed to upload file: ".substr($response, 0, strpos($response, "\r\n")));
}

echo "File uploaded successfully";

 

 

 

Author

Admin

Follow Me
Other Articles
Previous

10 proven ways to increase web traffic

Next

Uploading a File to Amazon S3 using PHP Code

FIFA World Cup 2026 Predict and Win by SportsGuff

Recent Posts

  • Unpacking Nepal’s Record Rs 2.12 Trillion Budget and What It Means for You
  • How to Write a Strong Scholarship Application: The Ultimate Step-by-Step Guide
  • How to Prepare for Exams Without Stress: The Ultimate Science-Backed Guide
  • Chiranjibi Adhikari Appointed Acting President of CAN Federation
  • How to Design a Student Marksheet Using HTML and CSS

Tags

adsense ai animate animation animation using HTML and CSS API blog calculator chatgpt Cryptocurrency CSS css animation design Email Facebook featured filemanager file manager free template google htaccess HTML image Instagram interview javascript JQuery jquery ui NADA AutoShow NADA Auto Show 2024 password PHP Progressive Web App PWA QR random react reactjs Rotate travel Twitter vpn youthforum youthsforum youtube

About Us

At Youths Forum, we are passionate about sharing knowledge that empowers students, educators, professionals, and technology enthusiasts.

Our Mission

Our mission is simple: to make technology and education accessible, understandable, and beneficial for everyone. We strive to create content that helps our readers learn new skills and stay updated with industry developments.

RSS RSS

  • Unpacking Nepal’s Record Rs 2.12 Trillion Budget and What It Means for You Admin
  • How to Write a Strong Scholarship Application: The Ultimate Step-by-Step Guide Admin
  • How to Prepare for Exams Without Stress: The Ultimate Science-Backed Guide Admin

Quick Links

  • Stock Market Live
  • Parliament Election 2082
Copyright 2026 — Youths Forum. All rights reserved. Blogsy WordPress Theme