Comments (5)
Hi @uprise10 ,
I'm not sure if this would work but maybe using this public static method: put_uploaded_file_to_blob_storage()
https://github.com/10up/windows-azure-storage/blob/master/includes/class-windows-azure-helper.php#L404
You would have to provide the parameters of the method, so i think if gravity forms already moved the file to local uploads it may work.
Best regards,
from windows-azure-storage.
Hi, thanks for this. In the meantime we got this working with the following code. This might be useful for other users who run into this problem.
It's a bit hardcoded, but someone who knows what he/she is doing can easily fix that :-)
class HandleUploads {
private static $instance;
public function __construct() {
$this->run();
}
public function run() {
add_action( 'gform_after_submission', [ $this, 'process_uploads_to_azure' ], 10 );
}
public function process_uploads_to_azure( $entry ) {
if( ! class_exists( 'Windows_Azure_Helper' ) ) {
return false;
}
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$upload_dir = wp_upload_dir();
// Determine file.
$file_url = $entry[8];
$file_url = json_decode( $file_url )[0];
// Generate correct paths.
$url_parts = parse_url( $file_url );
$file_path = str_replace( '/media/', '', $url_parts['path'] );
$full_path = $upload_dir['basedir'] . '/' . $file_path;
// Upload the file to Azure.
\Windows_Azure_Helper::put_uploaded_file_to_blob_storage( 'media', $file_path, $full_path );
return true;
}
/**
* Returns an instance of this class. An implementation of the singleton design pattern.
*
* @return object A reference to an instance of this class.
* @since 1.0.0
*/
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new HandleUploads();
}
return self::$instance;
}
}
from windows-azure-storage.
@uprise10 where specifically did you place this code?
from windows-azure-storage.
@thebriantucker we placed it in a separate class, but in fact you can place the code anywhere, for example in your functions.php. then you could rewrite it a bit:
<?php
add_action( 'gform_after_submission', 'yourprefix_process_uploads_to_azure', 10 );
function yourprefix_process_uploads_to_azure( $entry ) {
if( ! class_exists( 'Windows_Azure_Helper' ) ) {
return false;
}
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$upload_dir = wp_upload_dir();
// Determine file.
$file_url = $entry[8];
$file_url = json_decode( $file_url )[0];
// Generate correct paths.
$url_parts = parse_url( $file_url );
$file_path = str_replace( '/media/', '', $url_parts['path'] );
$full_path = $upload_dir['basedir'] . '/' . $file_path;
// Upload the file to Azure.
\Windows_Azure_Helper::put_uploaded_file_to_blob_storage( 'media', $file_path, $full_path );
return true;
}
from windows-azure-storage.
@uprise10 thank you so much for the fast response we will give it a go and provide feedback for others much appreciated.
from windows-azure-storage.
Related Issues (20)
- The plugin hasn't been tested with the latest version of WordPress
- IMG Broken after CNAME change HOT 1
- Add a 'Replace Media File' option
- WP 6.2.2 error HOT 3
- Release version 4.3.5
- `DEV_STORE_KEY` replacement HOT 1
- Add PHP checks
- moving assets to azure storage
- The plugin hasn't been tested with the latest version of WordPress HOT 1
- Webp copy of original jpeg image not uploading to Azure Storage
- Upgrade Cypress to version 13
- Using sas token to upload
- Need the images to be uploaded to wp-content/uploads/ HOT 3
- Retirement notice: The Azure Storage PHP client libraries will be retired on 17 March 2024
- Release version 4.4.0
- Update Azure Blob API to latest version
- The plugin hasn't been tested with an upcoming version of WordPress HOT 1
- Incorrect Content-Type being applied to uploaded files in v 4.4.0 HOT 3
- Release version 4.4.1
- The plugin hasn't been tested with an upcoming version of WordPress HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windows-azure-storage.