GithubHelp home page GithubHelp logo

Comments (5)

oscarssanchez avatar oscarssanchez commented on July 17, 2024

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.

uprise10 avatar uprise10 commented on July 17, 2024

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.

thebriantucker avatar thebriantucker commented on July 17, 2024

@uprise10 where specifically did you place this code?

from windows-azure-storage.

uprise10 avatar uprise10 commented on July 17, 2024

@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.

thebriantucker avatar thebriantucker commented on July 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.