Skip to content

Commit 7ff62e5

Browse files
author
David Cramer
authored
Merge pull request #215 from cloudinary/add/allow-cloud-change
set header to file if cloud_name sync type.
2 parents 3d023b0 + 494bf77 commit 7ff62e5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ function ( $item ) use ( $transformation_index ) {
228228
* @param string|null $public_id The Public ID to get a url for.
229229
* @param array $args Additional args.
230230
* @param array $size The WP Size array.
231+
* @param bool $clean Flag to produce a non variable size url.
231232
*
232233
* @return string
233234
*/
@@ -398,10 +399,11 @@ public function upload_large( $attachment_id, $args ) {
398399
* @param int $attachment_id Attachment ID to upload.
399400
* @param array $args Array of upload options.
400401
* @param array $headers Additional headers to use in upload.
402+
* @param bool $try_remote Flag to try_remote upload.
401403
*
402404
* @return array|\WP_Error
403405
*/
404-
public function upload( $attachment_id, $args, $headers = array() ) {
406+
public function upload( $attachment_id, $args, $headers = array(), $try_remote = true ) {
405407

406408
$resource = ! empty( $args['resource_type'] ) ? $args['resource_type'] : 'image';
407409
$resource = $this->convert_resource_type( $resource );
@@ -415,7 +417,7 @@ public function upload( $attachment_id, $args, $headers = array() ) {
415417
$disable_https_fetch = false;
416418
}
417419
// Check if we can try http file upload.
418-
if ( empty( $headers ) && empty( $disable_https_fetch ) ) {
420+
if ( empty( $headers ) && empty( $disable_https_fetch ) && true === $try_remote ) {
419421
$args['file'] = $file_url;
420422
} else {
421423
// We should have the file in args at this point, but if the transient was set, it will be defaulting here.

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ public function setup() {
201201
*/
202202
public function upload_asset( $attachment_id ) {
203203

204-
$type = $this->sync->get_sync_type( $attachment_id );
205-
$options = $this->media->get_upload_options( $attachment_id );
206-
$public_id = $options['public_id'];
204+
$type = $this->sync->get_sync_type( $attachment_id );
205+
$options = $this->media->get_upload_options( $attachment_id );
206+
$public_id = $options['public_id'];
207+
$try_remote = 'cloud_name' === $type ? false : true;
207208

208209
// Add the suffix before uploading.
209210
if ( $this->media->get_public_id( $attachment_id ) === $public_id ) {
@@ -215,7 +216,7 @@ public function upload_asset( $attachment_id ) {
215216
}
216217

217218
// Run the upload Call.
218-
$result = $this->connect->api->upload( $attachment_id, $options );
219+
$result = $this->connect->api->upload( $attachment_id, $options, array(), $try_remote );
219220

220221
if ( ! is_wp_error( $result ) ) {
221222

0 commit comments

Comments
 (0)