Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
seeyousurf  
#1 Posted : Thursday, October 1, 2009 7:29:11 AM(UTC)
seeyousurf

Rank: Member

Groups: Member
Joined: 5/19/2009(UTC)
Posts: 20

image uploader supports sending multiple files to Amazon S3?
I have a problem when I start to upload 10 pictures on amazon I am 8.
Why?
is it normal?

every time I upload I do not load all the photos but only a part.

thanks
Alex Kon  
#2 Posted : Thursday, October 1, 2009 5:00:50 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Administration
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello,

Yes, ImageUploader supports upload to Amazon S3. The only restriction in such case is to send single file in a single POST request. Simplest way to do this is to set ImageUploader.FilesPerOnePackageCount parameter to 1 and configure it to prepare single uploaded file for each input file. E.g. send only source file, or send only one thumbnail for each source file.

There is also more sophisticated sample which demonstrates how to upload several derivative files from single source file: see post by Dmitry (August 01, 2009).

Unfortunately I've never faced behaviour you described - when only part of all photos is uploaded. Try to check PolicyExpiration property - maybe it expires before upload ends. But it's default value is about 24 hours...

I recommend you to create support case with full description of your issue and attach code sample and all error messages you got. And we will try to solve the issue.

seeyousurf  
#3 Posted : Thursday, October 1, 2009 7:13:22 PM(UTC)
seeyousurf

Rank: Member

Groups: Member
Joined: 5/19/2009(UTC)
Posts: 20

<?php
//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
//Do not forget about the slash in the end of the folder name.
$galleryPath = "d:/...";
$absGalleryPath = realpath($galleryPath) . "/";
$absThumbnailsPath = realpath($galleryPath . "Thumbnails/") . "/";

function saveUploadedFiles()
{
global $absGalleryPath, $absThumbnailsPath;

//First of all, clear files and data uploaded at previous time.

//Delete source files.
//$handle = opendir($absGalleryPath);

//while (false !== ($file = readdir($handle)))
//{
//if (is_file($absGalleryPath . $file))
//{
//unlink($absGalleryPath . $file);
//}
//}
//closedir($handle);

//Delete thumbnails
//$handle = opendir($absThumbnailsPath);
//while (false !== ($file = readdir($handle)))
//{
//if (is_file($absThumbnailsPath . $file))
//{
//unlink($absThumbnailsPath . $file);
//}
//}
//closedir($handle);

//NOTE: If you do not want to delete previously uploaded files, just
//remove or comment out the code above.

//Create XML file which will keep information about files (image dimensions, description, etc).
//XML is used solely for brevity. In real-life application most likely you will use database instead.
$descriptions = new DOMDocument('1.0');
$descriptions->appendChild($descriptions->createElement("files"));

//Get total number of uploaded files (all files are uploaded in a single package).
$fileCount = $_POST["FileCount"];
$author = $_GET ["id"];
$id_spot = $_POST['id_spot'];
$prezzo = $_POST['prezzo'];
$valuta = $_POST['valuta'];
$ID_Album = $_GET['id_album'];
$id = $_GET['id'];
$dataalbum = $_POST['data'];

//This value will keep a total size of actually uploaded images. It will be displayed
//so that you could compare how many bytes you save.
$totalUploadedFileSize = 0;

$db_host = "localhost";
$db_user = "";
$db_password = "";
$db_name = "";
$conn = mysql_connect($db_host, $db_user, $db_password);
if ($conn == FALSE)
die ("Errore nella connessione. Verificare i parametri nel file");
mysql_select_db($db_name, $conn)
or die ("Errore nella selezione del database. Verificare i parametri nel file");
$query="Insert Into tb_album (id_album,ID_account,Data_album) values ('$ID_Album','$id','$dataalbum')";
$result = mysql_query ($query, $conn) or die(mysql_error());

//include the S3 class
if (!class_exists('S3'))require_once('S3.php');

//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', 'Accesskey');
if (!defined('awsSecretKey')) define('awsSecretKey', 'SecretKey');

//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);

$s3->putBucket("Bucket name", S3::ACL_PUBLIC_READ);

//Iterate through uploaded data and save the original file, thumbnail, and description.
for ($i = 1; $i <= $fileCount; $i++)
{
//Get the first thumbnail and save it to disk. It stores 1200x1200 optimized image.
$thumbnail1Field = "Thumbnail1_" . $i;
if (!$_FILES[$thumbnail1Field]['size'])
{
return;
}
$fileName = getSafeFileName(basename($_POST["FileName_" . $i]));

//move the file
$s3->putObjectFile($_FILES[$thumbnail1Field]['tmp_name'], "folder", $ID_Album . "/" . "Filebig" . "/" . $fileName, S3::ACL_PUBLIC_READ);


$thumbnail2Field = "Thumbnail2_" . $i;
if (!$_FILES[$thumbnail2Field]['size'])
{
return;
}
$s3->putObjectFile($_FILES[$thumbnail2Field]['tmp_name'], "folder", $ID_Album . "/" . "Filesmall" . "/" . $fileName, S3::ACL_PUBLIC_READ);

//move_uploaded_file($_FILES[$thumbnail1Field]['tmp_name'], $absGalleryPath . "/" . $fileName);

//$totalUploadedFileSize = $totalUploadedFileSize + filesize($absGalleryPath . "/" . $fileName);

$ID_Album = $_GET['id_album'];
$id = $_GET['id'];
$dataalbum = $_POST['data'];
//$size=filesize($absGalleryPath . "/" . $fileName);
$date = date("Y-m-d");
//$datefoto = $_POST['datafoto'];
//$timefoto = $_POST['orafoto'];
$query2="Insert Into tb_immagini (NomeFoto,ID_account,SizeFoto,Datainserimento,Datafoto,OraFoto,Convalida,ID_Album,dataalbum,id_spot,prezzo,valuta) values ('$fileName','$id','$size','$date','$datefoto','$timefoto','1','$ID_Album','$dataalbum','$id_spot','$prezzo','$valuta')";
$result2 = mysql_query ($query2, $conn) or die(mysql_error());

//Get the second thumbnail and save it to disk. It stores 120x120 preview image.

//move_uploaded_file($_FILES[$thumbnail2Field]['tmp_name'], $absGalleryPath . "/Thumbnails/" . $fileName . ".jpg");

//Save file info.
$xmlFile = $descriptions->createElement("file");
$xmlFile->setAttribute("name", $fileName);
$xmlFile->setAttribute("width", $_POST ['Width_' . $i]);
$xmlFile->setAttribute("height", $_POST ['Height_' . $i]);
$xmlFile->setAttribute("author", $author);
$descriptions->documentElement->appendChild($xmlFile);
}

//Write both optimized and source file sizes for comparison.
$descriptions->documentElement->setAttribute("totalSourceFileSize", $_POST ['TotalSourceFileSize']);
$descriptions->documentElement->setAttribute("totalUploadedFileSize", ceil($totalUploadedFileSize / 1024));

$descriptions->save($absGalleryPath . "Descriptions.xml");
}

//This method verifies whether file with such name already exists
//and if so, construct safe filename name (to avoid collision).
function getSafeFileName($fileName)
{
global $absGalleryPath;

$newFileName = $fileName;
$j = 1;
while (file_exists($absGalleryPath . "/" . $newFileName))
{
$newFileName = $j . "_" . $fileName;
$j = $j + 1;
}
return $newFileName;
}

saveUploadedFiles();
?>



<script runat="server">
//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
//Do not forget about the slash in the end of the folder name.
private string galleryPath = "D:/home/seeyousurf.com/httpdocs/myphoto/";

private void Page_Load(System.Object sender, System.EventArgs e)
{
//First of all, clear data uploaded at previous time.

//Delete source files
DirectoryInfo dir = new DirectoryInfo(Server.MapPath(galleryPath));
foreach (FileInfo file in dir.GetFiles())
{
file.Delete();
}

//Delete thumbnails
dir = new DirectoryInfo(Server.MapPath(galleryPath) + "/Thumbnails");
foreach (FileInfo file in dir.GetFiles())
{
file.Delete();
}

//NOTE: If you do not want to delete previously uploaded files, just
//remove or comment out the code above.

//Create XML file which will keep information about files (image dimensions, description, etc).
//XML is used solely for brevity. In real-life application most likely you will use database instead.
XmlDocument descriptions = new XmlDocument();
descriptions.AppendChild(descriptions.CreateElement("files"));

//Get total number of uploaded files (all files are uploaded in a single package).
int fileCount = Int32.Parse(Request.Form["FileCount"]);

//This value will keep a total size of actually uploaded images. It will be displayed
//so that you could compare how many bytes you save.
long totalUploadedFileSize = 0;

//Iterate through uploaded data and save the large and small thumbnails.
for (int i = 1; i <= fileCount; i++)
{
//Get the first thumbnail and save it to disk. It stores 1200x1200 optimized image.
HttpPostedFile thumbnail1File = Request.Files["Thumbnail1_" + i];
string fileName = GetSafeFileName(Path.GetFileName(Request.Form["FileName_" + i]));
thumbnail1File.SaveAs(Server.MapPath(galleryPath + fileName));

totalUploadedFileSize += thumbnail1File.InputStream.Length;

//Get the second thumbnail and save it to disk. It stores 120x120 preview image.
HttpPostedFile thumbnail2File = Request.Files["Thumbnail2_" + i];
thumbnail2File.SaveAs(Server.MapPath(galleryPath + "Thumbnails/" + fileName + ".jpg"));

//Save file info.
XmlElement xmlFile = descriptions.CreateElement("file");
xmlFile.SetAttribute("name", fileName);
xmlFile.SetAttribute("width", Request.Form["Width_" + i]);
xmlFile.SetAttribute("height", Request.Form["Height_" + i]);

descriptions.DocumentElement.AppendChild(xmlFile);
}

//Write both optimized and source file sizes for comparison.
descriptions.DocumentElement.SetAttribute("totalSourceFileSize", Request.Form["TotalSourceFileSize"]);
descriptions.DocumentElement.SetAttribute("totalUploadedFileSize", Convert.ToString(Math.Ceiling((double)(totalUploadedFileSize / 1024))));

//Save the description XML file.
descriptions.Save(Server.MapPath(galleryPath + "Descriptions.xml"));
}

//This method verifies whether file with such name already exists
//and if so, construct safe filename name (to avoid collision).
private string GetSafeFileName(string fileName)
{
string newFileName = fileName;
int j = 1;
while (File.Exists(Server.MapPath(galleryPath + newFileName)))
{
newFileName = j + "_" + fileName;
j++;
}
return newFileName;
}
</script>

Thanks
regards
Alex Kon  
#4 Posted : Sunday, October 4, 2009 5:42:04 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Administration
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello,

Maybe I missed something in the posted code, but it seems that you actually upload files to your own server, which forwards them to amazon bucket. This approach may work, but if you experience troubles with it, I'm not the right person to ask, sorry. I'm not competent with your S3 codebase, like s3.php and can't help with that.

Another way is to use ImageUploader to upload files directly to amazon S3. In addition to the sample I mentioned in previous post, I've attached another one, which shows straight file upload to amazon bucket. Note, that sample requires Aurigma PHPLibrary to work (which is installed with all other ImageUploader scripts).

Best regards,
Alex Kon

Edited by user Sunday, October 4, 2009 5:46:05 PM(UTC)  | Reason: Not specified

File Attachment(s):
amazonS3_sample.zip (2kb) downloaded 17 time(s).
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.