/// <summary> /// Write the multipart/form-data for this request for all fields except the file data to a stream /// </summary> internal void WriteFormData(string boundary, Stream outputStream) { if (!String.IsNullOrEmpty(this.Key)) { WriteFormDatum(outputStream, S3Constants.PostFormDataObjectKey, this.Key, boundary); } WriteFormDatum(outputStream, S3Constants.PostFormDataAcl, this.CannedACL, boundary); if (this._isSetStorageClass) { WriteFormDatum(outputStream, HeaderKeys.XAmzStorageClassHeader, this.StorageClass, boundary); } if (this._isSetActionStatus) { WriteFormDatum(outputStream, S3Constants.PostFormDataStatus, ((Int32)this.SuccessActionStatus).ToString(CultureInfo.InvariantCulture), boundary); } if (!String.IsNullOrEmpty(this.SuccessActionRedirect)) { WriteFormDatum(outputStream, S3Constants.PostFormDataRedirect, this.SuccessActionRedirect, boundary); } if (String.IsNullOrEmpty(this.ContentType)) { if (this.Key.IndexOf('.') > -1) { this.ContentType = AmazonS3Util.MimeTypeFromExtension(this.Key.Substring(this.Key.LastIndexOf('.'))); } else if (!String.IsNullOrEmpty(this.Path) && this.Path.IndexOf('.') > -1) { this.ContentType = AmazonS3Util.MimeTypeFromExtension(this.Key.Substring(this.Path.LastIndexOf('.'))); } } WriteFormDatum(outputStream, S3Constants.PostFormDataContentType, this.ContentType, boundary); if (this.SignedPolicy != null && !string.IsNullOrEmpty(this.SignedPolicy.SecurityToken)) { this.Metadata[S3Constants.PostFormDataSecurityToken] = this.SignedPolicy.SecurityToken; } foreach (var kvp in this.Metadata) { var metakey = kvp.Key.StartsWith(S3Constants.PostFormDataXAmzPrefix, StringComparison.Ordinal) ? kvp.Key : S3Constants.PostFormDataMetaPrefix + kvp.Key; WriteFormDatum(outputStream, metakey, kvp.Value, boundary); } if (this.SignedPolicy != null) { WriteFormDatum(outputStream, S3Constants.PostFormDataAccessKeyId, this.SignedPolicy.AccessKeyId, boundary); WriteFormDatum(outputStream, S3Constants.PostFormDataPolicy, this.SignedPolicy.Policy, boundary); WriteFormDatum(outputStream, S3Constants.PostFormDataSignature, this.SignedPolicy.Signature, boundary); } }
/// <summary> /// Write the multipart/form-data for this request for all fields except the file data to a stream /// </summary> internal void WriteFormData(string boundary, Stream outputStream) { var sb = new StringBuilder(); if (!String.IsNullOrEmpty(this.Key)) { WriteFormDatum(outputStream, S3Constants.PostFormDataObjectKey, this.Key, boundary); } WriteFormDatum(outputStream, S3Constants.PostFormDataAcl, S3Constants.CannedAcls[(int)this.CannedACL], boundary); if (this._isSetStorageClass) { WriteFormDatum(outputStream, S3Constants.AmzStorageClassHeader, S3Constants.StorageClasses[(int)this.StorageClass], boundary); } if (this._isSetActionStatus) { WriteFormDatum(outputStream, S3Constants.PostFormDataStatus, ((Int32)this.SuccessActionStatus).ToString(), boundary); } if (!String.IsNullOrEmpty(this.SuccessActionRedirect)) { WriteFormDatum(outputStream, S3Constants.PostFormDataRedirect, this.SuccessActionRedirect, boundary); } if (String.IsNullOrEmpty(this.ContentType)) { if (this.Key.IndexOf('.') > -1) { this.ContentType = AmazonS3Util.MimeTypeFromExtension(this.Key.Substring(this.Key.LastIndexOf('.'))); } else if (!String.IsNullOrEmpty(this.Path) && this.Path.IndexOf('.') > -1) { this.ContentType = AmazonS3Util.MimeTypeFromExtension(this.Key.Substring(this.Path.LastIndexOf('.'))); } } WriteFormDatum(outputStream, S3Constants.PostFormDataContentType, this.ContentType, boundary); foreach (var kvp in this.Metadata) { var metakey = kvp.Key.StartsWith(S3Constants.PostFormDataXAmzPrefix) ? kvp.Key : S3Constants.PostFormDataMetaPrefix + kvp.Key; WriteFormDatum(outputStream, metakey, kvp.Value, boundary); } if (this.SignedPolicy != null) { WriteFormDatum(outputStream, S3Constants.PostFormDataAccessKeyId, this.SignedPolicy.AccessKeyId, boundary); WriteFormDatum(outputStream, S3Constants.PostFormDataPolicy, this.SignedPolicy.Policy, boundary); WriteFormDatum(outputStream, S3Constants.PostFormDataSignature, this.SignedPolicy.Signature, boundary); } }
internal void WriteFormData(string boundary, Stream outputStream) { if (!string.IsNullOrEmpty(Key)) { WriteFormDatum(outputStream, S3Constants.PostFormDataObjectKey, Key, boundary); } WriteFormDatum(outputStream, S3Constants.PostFormDataAcl, ConstantClass.op_Implicit(CannedACL), boundary); if (_isSetStorageClass) { WriteFormDatum(outputStream, "x-amz-storage-class", ConstantClass.op_Implicit(StorageClass), boundary); } if (_isSetActionStatus) { WriteFormDatum(outputStream, S3Constants.PostFormDataStatus, ((int)SuccessActionStatus).ToString((IFormatProvider)CultureInfo.InvariantCulture), boundary); } if (!string.IsNullOrEmpty(SuccessActionRedirect)) { WriteFormDatum(outputStream, S3Constants.PostFormDataRedirect, SuccessActionRedirect, boundary); } if (string.IsNullOrEmpty(ContentType)) { if (Key.IndexOf('.') > -1) { ContentType = AmazonS3Util.MimeTypeFromExtension(Key.Substring(Key.LastIndexOf('.'))); } else if (!string.IsNullOrEmpty(Path) && Path.IndexOf('.') > -1) { ContentType = AmazonS3Util.MimeTypeFromExtension(Key.Substring(Path.LastIndexOf('.'))); } } WriteFormDatum(outputStream, S3Constants.PostFormDataContentType, ContentType, boundary); if (SignedPolicy != null && !string.IsNullOrEmpty(SignedPolicy.SecurityToken)) { Metadata[S3Constants.PostFormDataSecurityToken] = SignedPolicy.SecurityToken; } foreach (KeyValuePair <string, string> metadatum in Metadata) { string name = metadatum.Key.StartsWith(S3Constants.PostFormDataXAmzPrefix, StringComparison.Ordinal) ? metadatum.Key : (S3Constants.PostFormDataMetaPrefix + metadatum.Key); WriteFormDatum(outputStream, name, metadatum.Value, boundary); } if (SignedPolicy != null) { WriteFormDatum(outputStream, S3Constants.PostFormDataAccessKeyId, SignedPolicy.AccessKeyId, boundary); WriteFormDatum(outputStream, S3Constants.PostFormDataPolicy, SignedPolicy.Policy, boundary); WriteFormDatum(outputStream, S3Constants.PostFormDataSignature, SignedPolicy.Signature, boundary); } }