phpamazon-web-servicesamazon-s3laravel-5laravel-medialibrary

How does Laravel decide where to save temp files?


I am using this image library that uploads images to S3.

At first it saves the image as a temp file on local machine, then it uploads it to S3.

My issue is that using certain functions temp files get uploaded to C:\\xampp\\tmp/ and using other functions the temp file gets uploaded to C:\Users\myUser\AppData\Local\Temp.

My question is that where does this gets decided? and how to configure it?

I'm using Win10 machine and Postman.

This is the function that uploads the image to C:\Users\myUser\AppData\Local\Temp:

 * @param Request $request
 *
 * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded
 */
public function coverPhotoFromRequest( Request $request ) {
  if ( $request->hasFile( 'cover_photo' ) ) {
    $this->clearMediaCollection( 'cover' );
    $this->addMedia( $request->file( 'cover_photo' ) )->toMediaCollection( 'cover' );
  }
}

This very similar function uploads temp files to C:\\xampp\\tmp/:

/**
 * @helper handles the profile photo from request or link
 *
 * @param mixed $photo
 *
 * @return \Spatie\MediaLibrary\Media
 * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded
 * @throws \Spatie\MediaLibrary\FileAdder\FileDoesNotExist
 */
public function profilePhoto( $photo = null ) {
  if ( Ut::isUrl( $photo ) ) {
    return $this->clearMediaCollection( 'profile' )->addMediaFromUrl( $request->file( 'profile_photo' ) )->toMediaCollection( 'profile' );
  }

  if ( $photo instanceof UploadedFile ) {
    return $this->clearMediaCollection( 'profile' )->addMedia( $request->file( 'profile_photo' ) )->toMediaCollection( 'profile' );
  }
}

This is the path to project:

C:\Users\myUser\Projects\images\api

The problem is that when I push the code to the server, the same problem happens.

I checked config file and I have this:

'temporary_directory_path' => storage_path('medialibrary/temp'),

But sometimes it still sends to /xampp and C:\Users\myUser\AppData\


Solution

  • The library has a config directive for the temp path 'temporary_directory_path' listed in the docs https://docs.spatie.be/laravel-medialibrary/v7/installation-setup.

    Does setting that help?