Code Monkey home page Code Monkey logo

s3-objects-stream-zip-php's People

Contributors

giovanigenerali avatar peter279k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

s3-objects-stream-zip-php's Issues

Suggestion

I have a suggestion not to raise an exception when many files are passed and some of them do not exist, even though the parameter $checkObjectExist.

In the file src\S3ObjectsStreamZip.php

foreach ($objects as $object) {
	/*
	 * Added this IF to generate even if the current file doesn't exist
	 */
	if (file_exists($objectDir)) {
		$objectName = isset($object["name"]) ? $object["name"] : basename($object["path"]);

		$context = stream_context_create(array(
		  "s3" => array("seekable" => true)
		));

		$request = $this->s3Client->createPresignedRequest(
		  $this->s3Client->getCommand("GetObject", [
			"Key" => $object["path"],
			"Bucket" => $bucket,
		  ]),
		  "+1 day"
		);

		$tmpfile = tempnam(sys_get_temp_dir(), crc32(time()));

		$httpClient->request("GET", (string) $request->getUri(), array(
		  "synchronous"	=> true,
		  "sink" => fopen($tmpfile, "w+")
		));

		if ($stream = fopen($tmpfile, "r", false, $context)) {
		  $zip->addFileFromStream($objectName, $stream);
		}
	}
}

Connection With S3 using IAm role

how can i get connection with S3 using IAM role? as in IAM role credentials are not passed while connection make. but in this case credentials is required to make connection with S3.

A lot of content is generated in `/tmp`

The intermediate files that are downloaded are stored in /tmp, which makes it use a lot of space unnecessarily.

You could add a call to the unlink function to delete the file after use and this would improve a lot and avoid the need to go around deleting temporary files.

In this line:
https://github.com/wgenial/s3-objects-stream-zip-php/blob/master/src/S3ObjectsStreamZip.php#L69

        ....
        $tmpfile = tempnam(sys_get_temp_dir(), crc32(time()));

        $httpClient->request("GET", (string) $request->getUri(), array(
          "synchronous" => true,
          "sink" => fopen($tmpfile, "w+")
        ));
        
        if ($stream = fopen($tmpfile, "r", false, $context)) {
          $zip->addFileFromStream($objectName, $stream);
        }
        
        unlink($tmpfile);   // <-- This line will tell PHP that we no longer need the file.
      }
      

Optional file validation

In my case where I was trying to zip up thousands of photos at once, the file validation was making it take 2-3 minutes before the zip actually started streaming. While I get the value of making sure all of the files exist before doing this, I think it makes sense to have an option to silently skip those files during streaming instead of trying to validate them all up front.

Which IAM policy?

Do you happen to know which IAM policy is needed to permit the fopen in this library?

image

Update dependencies

Can you please update the dependencies, since maennchen/zipstream-php has released there 1.0.

Thanks

Corrupted Zip

Hello,

I used your implementation for downloading S3 files through PHP like this

`<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include DIR.'/../vendor/autoload.php';

use Aws\S3\Exception\S3Exception;
use WGenial\S3ObjectsStreamZip\S3ObjectsStreamZip;
use WGenial\S3ObjectsStreamZip\Exception\InvalidParamsException;

try {

header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="imagenes.zip"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$zipStream = new S3ObjectsStreamZip(array(
  'version' => 'latest', 
  'region' => 'us-west-2', 
  'credentials' => array(
    'key'    => 'key',
    'secret' => 'secret'
  )
));
$objectsA = array();
$files = json_decode($_POST['fileData']);
foreach ($files as $file) {
  //array_push($objectsA, $file);
  array_push($objectsA, array(
    'path' => 'asseetFiles/'.$file->file,
    'name' => 'asseetFiles/'.$file->name
  ));
}
$bucket = 'kaab-files'; // required


$zipname = 'imagenes.zip'; // required

$checkObjectExist = false; // no required | default = false

$zipStream->zipObjects($bucket, $objectsA, $zipname, $checkObjectExist);

}
catch (InvalidParamsException $e) {
echo $e->getMessage();
}
catch (S3Exception $e) {
echo $e->getMessage();
}
`
and some times the result file is corrupted, not all files are included,

You have any idea how can i fix that?

Allow anonymous clients.

It is a recommended security practice to use machine level IAM roles rather than providing credentials to the client. This is done by using an anonymous client. You can do this by setting credentials to false if a secret and key are not provided.

Invalid zip on Windows most of the time

I have the script working and can download zipped files from my website. On my Mac it works and I can open them.
On Windows it gives an 'Invalid' error when the zip is above 1MB. Any zip below that opens fine.

Any clue what the problem is?

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.