PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] How to upload image to digital Ocean Spaces using AWS SDK for Yii2?

 November 08, 2022     digital-ocean, php, yii2     No comments   

Issue

Since Digital Ocean Spaces API is compatible with AWS SDK, how to upload images to Digital Ocean Spaces programmatically using AWS SDK for Yii2?

Here my details

Good, we have the following data: 
1. endpoint: fra1.digitaloceanspaces.com
2. bucket name: dev-abc
3. api key: xxxxxxxxxxxxx and api secret: xxxxxxx
4. The url that you need to use to deliver assets is https://dev-abc

I have tried with this code whis is not working

$uploader = new FileUpload(FileUpload::S_S3, [
    'version' => 'latest',
    'region' => 'fra1',
    'endpoint' => 'https://fra1.digitaloceanspaces.com',
    'credentials' => [
        'key' => 'xxxxxxxxxxxxx ',
        'secret' => 'xxxxxxx'
    ],
    'bucket' => 'dev-abc'
]);

Solution

Here how i mange to go this

Added the three libraries gulp,gulp-awspublish,gulp-rename

var gulp = require('gulp');
var awspublish = require('gulp-awspublish');
var rename = require('gulp-rename');

var publisherDev = awspublish.create({
  region: 'fra1',
  params: {
    Bucket: 'dev-static-abc-ro'
  },
  accessKeyId: 'XCCCCCZX',
  secretAccessKey: 'EDKDJKJDKDJ',
  endpoint: 'fra1.digitaloceanspaces.com'
});

Now added the function // dev server

gulp.task('dev', function() {
  // console.log("Hi! I'm Gulp default task root!");
  return gulp
    .src('./temp-dist/**')
    .pipe(
      rename(function(path) {
        path.dirname += '/assets';
        // path.basename += "-s3";
      })
    )
    .pipe(publisherDev.publish())
    .pipe(publisherDev.sync('assets/'))
    .pipe(awspublish.reporter());
});

Run the command

gulp dev



Answered By - rajwa766
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing