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

Notification

Icon
Error

Options
Go to last post Go to first unread
Dmitry.Obukhov  
#1 Posted : Tuesday, December 7, 2010 10:53:22 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups: Member
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Some of our users use Image Uploader to upload files to Amazon S3 storage, and ask us how to set content-type for these files. It is very simple.

To specify content-type value for uploaded files, you should add it using addCustomField(String,String) method:
Code:

// Add Content-Type value for uploaded images
uploader.metadata().addCustomField('Content-Type', 'image/jpeg');

Also you need to add specified content type to AWS policy. In our sample applications the code which generates these policies is located in the \ASP.NET\Samples_ImageUploaderAspNet\App_Code\AmazonS3Helper.cs file. You will need to add content type to ConstructPolicy method:
Code:

private static string ConstructPolicy(string bucket, DateTime expirationDate, string acl, string key)
	{
		// See about policy construction 
		// http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/HTTPPOSTForms.html#HTTPPOSTConstructPolicy	

		string policy = string.Format(@"
			{{ 'expiration': '{0}.000Z',
				'conditions': [
					{{ 'acl': '{1}' }},
					{{ 'bucket': '{2}' }},
					{{ 'success_action_status': '200' }},
					[ 'starts-with', '$key', '' ],
					[ 'starts-with', '$Content-Type', '' ],
				]
			}}", expirationDate.ToString("s"), acl, bucket);

		// Encode the policy using UTF-8.
		byte[] pb = System.Text.Encoding.UTF8.GetBytes(policy.ToString());

		// Encode those UTF-8 bytes using Base64 and return.
		return Convert.ToBase64String(pb);
	}

The complete ASP.NET sample application demonstrating how to set content-type is attached to this post.

P.S. If you use PHP, please let us know, and we will assist you in timely manner.

Edited by user Thursday, April 7, 2011 8:07:26 PM(UTC)  | Reason: Not specified

File Attachment(s):
iu7_AmazonS3.zip (2,413kb) downloaded 39 time(s).
Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
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.