How Do I access files via Uploads in PyroCMS? - pyrocms

I've uploaded an image; random.png with PyroCMS through the admin and placed it into a folder called "Portfolio Images" (the url slug is 'portfolio-images')
In my pages I want to be able to reference this image using a tag. How does the url slug work? I've tried http://mysite.com/portfolio-images/random.png - but it doesn't work.
Is there a way to maybe reference it via the {{ asset:image }} tag?
Thanks!

To display your image you can do :
there is a plugin for making file list the documentation is not yet available but you have a description of the plugin in the code in system/cms/modules/files/plugin.php
/**
* Files listing
*
* Creates a list of files
*
* Usage:
*
* {{ files:listing folder="home-slider" type="i" fetch="subfolder|root" }}
* // your html logic
* {{ /files:listing }}
*
* The tags that are available to use from this method are listed below
*
* {id}
* {folder_id}
* {user_id}
* {type}
* {name}
* {filename}
* {description}
* {extension}
* {mimetype}
* {width}
* {height}
* {filesize}
* {date_added}
*
* #return array
*/

Related

int-aws:s3-outbound-channel-adapter or int-aws:s3-outbound-gateway is not throwing any error when there is no access permission at bucket level

I am facing one issue in both int-aws:s3-outbound-gateway and int-aws:s3-outbound-channel-adapter . The issue is, Suppose if i don't have the bucket access permission which is already configured as a destination bucket the adapter should throw run time error in the console but I am not getting any error in the console and files are not moved to the respective destination.
Could you please advice on this
<int-aws:s3-outbound-channel-adapter
id="moverId"
channel="ChannelGateway"
transfer-manager="tf"
bucket-expression="bucketName"
key-expression="headers.file_name"
command="UPLOAD">
<int-aws:request-handler-advice-chain>
<ref bean="retryAdvice" />
</int-aws:request-handler-advice-chain>
</int-aws:s3-outbound-channel-adapter>
You don't get any errors because such an upload is an async operation.
The S3MessageHandler is fully based on the AWS S3 TransferManager. And when we upload the file into the remote bucket it is done by this operation:
/**
* <p>
* Schedules a new transfer to upload data to Amazon S3. This method is
* non-blocking and returns immediately (i.e. before the upload has
* finished).
* </p>
* <p>
* Use the returned <code>Upload</code> object to query the progress of the
* transfer, add listeners for progress events, and wait for the upload to
* complete.
* </p>
* <p>
* If resources are available, the upload will begin immediately. Otherwise,
* the upload is scheduled and started as soon as resources become
* available.
* </p>
* <p>
* If you are uploading <a href="http://aws.amazon.com/kms/">AWS
* KMS</a>-encrypted objects, you need to specify the correct region of the
* bucket on your client and configure AWS Signature Version 4 for added
* security. For more information on how to do this, see
* http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html#
* specify-signature-version
* </p>
*
* #param putObjectRequest
* The request containing all the parameters for the upload.
* #param progressListener
* An optional callback listener to receive the progress of the
* upload.
*
* #return A new <code>Upload</code> object to use to check the state of the
* upload, listen for progress notifications, and otherwise manage
* the upload.
*
* #throws AmazonClientException
* If any errors are encountered in the client while making the
* request or handling the response.
* #throws AmazonServiceException
* If any errors occurred in Amazon S3 while processing the
* request.
*/
public Upload upload(final PutObjectRequest putObjectRequest,
final S3ProgressListener progressListener)
Pay attention to the second argument if this method: the S3MessageHandler provides such a hook for your use case:
/**
* Specify a {#link S3ProgressListener} for upload and download operations.
* #param s3ProgressListener the {#link S3ProgressListener} to use.
* #see MessageS3ProgressListener
*/
public void setProgressListener(S3ProgressListener s3ProgressListener) {
And you need to track there a progressChanged(ProgressEvent progressEvent) for an appropriate ProgressEventType.

Overriding property name in Api Platform

Oke, so I have the following use case. On some of my entities I use a file entity for example with the organization logo.
Now I want users to post either a link (I will then async get the file) or a base64 has of the file. But when the user does a get I want to present an JSON representation of the file entity (that also includes size, a thumbnail link etc).
The current setup that I have is two different properties on my entity, one for reading and one for posting with different logic. And then an event listener that handels the logic. That’s all fine and all but it causes the user to post a postLogo property in their json file, I would hower like them to post to a logo property in their json file.
Is there an annotation that I can use (for example name on ApiProperty) to achieve this or do I need to override the serializer?
/**
* #var File The logo of this organisation
*
* #ORM\ManyToOne(targetEntity="File")
* #ApiProperty(
* attributes={
* "openapi_context"={
* "type"="#/components/schemas/File"
* }
* }
* )
* #Groups({"read"})
*/
public $logo;
/**
* #var string The logo of this organisation, a logo can iether be posted as a valid url to that logo or a base64 reprecentation of that logo.
*
* #ApiProperty(
* attributes={
* "openapi_context"={
* "type"="url or base64"
* }
* }
* )
* #Groups({"write"})
*/
public $postLogo;
You can add a setter with a SerializedName annotation. Something like this should work
/**
* #Groups({"write"})
* #SerializedName("logo")
*
*/
public function setPostLogo($value)
{
$this->postLogo = $value;
}

Swagger.php : how to change POST request header Content-type

I use lib: darkaonline/l5-swagger (^5.5) (which contains swagger-php + swagger-ui), I need to change header Content-Type in my POST request to upload file (to read it in Laravel Input::file('photo') ). I read that I should add consumes and produces parameters to my swagger - this is what i have:
/**
*
* Create Building Photo
*
* #SWG\Post(
* path="/api/v1/buildings/{buildingId}/photo",
* security={{"oauth2": {"*"}}},
* tags={"building"},
* consumes={"text/plain", "application/json"},
* produces={"text/plain", "application/json"},
* description="Update building",
* #SWG\Parameter(
* name="buildingId",
* in="path",
* description="Building id",
* required=true,
* type="number",
* ),
* #SWG\Parameter(
* name="photo",
* in="formData",
* required=true,
* description="Building photo",
* type="file",
* ),
* #SWG\Response( response=200, description="ok"),
* #SWG\Response( response=404, description="Building not found"),
* )
*
*/
But in request Content-type and Accept I always get application/json and laravel is unable to read uploaded file (when I generate request using swagger-ui). How I should change above swagger to to allow laravel read Input::file('photo') form POST request generated by swagger-ui ?
This is solution:
* consumes={"multipart/form-data"},
* produces={"text/plain, application/json"},
:)
Please find solution here.
You should follow this guidelines to setup Swagger in Laravel with Passport authentication and much more
https://github.com/DarkaOnLine/L5-Swagger
Here, some listed issues that you may face during implementation.
https://github.com/DarkaOnLine/L5-Swagger/issues/57

How to use php-cs-fixer with vim for laravel?

I have installed php-cs-fixer & using with vim plugin https://github.com/stephpy/vim-php-cs-fixer. I am using custom config file from https://github.com/laravel/framework/blob/5.4/.php_cs. But I am having this issue where extra space after #param from comment block gets deleted.
How can I fix this? Thanks for in advance.
Laravel uses PSR2 coding standard.
From laravel.com about documentation -
Note that the #param attribute is followed by two spaces, the argument type, two more spaces, and finally the variable name:
/**
* Register a binding with the container.
*
* #param string|array $abstract
* #param \Closure|string|null $concrete
* #param bool $shared
* #return void
*/
public function bind($abstract, $concrete = null, $shared = false)
{
//
}
Thanks.
You are probably looking for "phpdoc_align" fixer. See docs:
Laravel uses many more from Symfony standard (marked by "#Symfony").
But the best way to find all fixers for Laravel, would be in PHP-CS-Fixer configuration in Laravel repostiory.

Find error line in AngularJS app

I just started to play with AngularJS and I got error below.
Error: Argument '?' is not a function, got Object
at assertArg (http://localhost/angular/project/scripts/vendor/angular.js:1039:11)
at assertArgFn (http://localhost/angular/project/scripts/vendor/angular.js:1049:3)
at http://localhost/angular/project/scripts/vendor/angular.js:4802:9
at http://localhost/angular/project/scripts/vendor/angular.js:4384:17
at forEach (http://localhost/angular/project/scripts/vendor/angular.js:137:20)
at nodeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4369:11)
at compositeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4015:15)
at compositeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4018:13)
at publicLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:3920:30)
at update (http://localhost/angular/project/scripts/vendor/angular.js:14202:11)
Now, my question is: Is there a way I can find line in .js file where error occurred?
I get line number in angular.js file on raised exception but there is too many files where
error can occur.
I tried with AngularJS Batarang, but this is more for debugging semantic not syntax errors.
Thanks.
It'll be easier if you link to the js files that would have caused this error.
From the angular.js source, https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js
it looks like a problem with instantiating the controller.
Here's the line that's causing assertion failure:
/**
* #ngdoc function
* #name ng.$controller
* #requires $injector
*
* #param {Function|string} constructor If called with a function then it's considered to be the
* controller constructor function. Otherwise it's considered to be a string which is used
* to retrieve the controller constructor using the following steps:
*
* * check if a controller with given name is registered via `$controllerProvider`
* * check if evaluating the string on the current scope returns a constructor
* * check `window[constructor]` on the global `window` object
*
* #param {Object} locals Injection locals for Controller.
* #return {Object} Instance of given controller.
*
* #description
* `$controller` service is responsible for instantiating controllers.
*
* It's just a simple call to {#link AUTO.$injector $injector}, but extracted into
* a service, so that one can override this service with {#link https://gist.github.com/1649788
* BC version}.
*/
return function(constructor, locals) {
if(isString(constructor)) {
var name = constructor;
constructor = controllers.hasOwnProperty(name)
? controllers[name]
: getter(locals.$scope, name, true) || getter($window, name, true);
======> assertArgFn(constructor, name, true);
}
return $injector.instantiate(constructor, locals);
};
It's unable to find the constructor for the controller.

Resources