public static string sendInvDoc2Cloud(FileUpload htmlFilePost, string InventoryHeader)
    {
        string docPath;
        string connStr = WebConfigurationManager.ConnectionStrings["eastManDB"].ConnectionString;

        if (string.IsNullOrEmpty(htmlFilePost.FileName) && string.IsNullOrEmpty(InventoryHeader))
        {
            return("Error - empty data passed");
        }


        if (CommonFunctions.IsValidDoc(htmlFilePost.PostedFile))
        {
            try
            {
                AmazonS3 myS3           = new com.amazonaws.s3.AmazonS3();
                DateTime myTime         = DateTime.Now;
                string   strMySignature = S3Helper.GetSignature(
                    mySecretAccessKeyId,
                    "PutObjectInline",
                    myTime);

                Grant   myGrant  = new com.amazonaws.s3.Grant();
                Grant[] myGrants = new Grant[1];
                com.amazonaws.s3.Group myGroup = new com.amazonaws.s3.Group();
                myGroup.URI        = "http://acs.amazonaws.com/groups/global/AllUsers";
                myGrant.Grantee    = myGroup;
                myGrant.Permission = Permission.READ;
                myGrants[0]        = myGrant;


                MetadataEntry myContentType = new MetadataEntry();
                myContentType.Name  = "ContentType";
                myContentType.Value = htmlFilePost.PostedFile.ContentType;

                MetadataEntry[] myMetaData = new MetadataEntry[1];
                myMetaData[0]       = myContentType;
                myContentType.Value = htmlFilePost.PostedFile.ContentType;

                string uploadFileName = @"InvDocs/orginal/"
                                        + Membership.GetUser().ProviderUserKey.ToString()
                                        + @"/" + "invDetails" +
                                        System.IO.Path.GetExtension(htmlFilePost.PostedFile.FileName);

                PutObjectResult myResult =
                    myS3.PutObjectInline(
                        awsDirName,
                        uploadFileName,
                        myMetaData,
                        htmlFilePost.FileBytes,
                        htmlFilePost.FileBytes.Length,
                        myGrants,
                        StorageClass.STANDARD,
                        true,
                        myAWSAccessKeyId,
                        S3Helper.GetTimeStamp(myTime),
                        true,
                        strMySignature, null
                        );
                docPath = uploadFileName;
            }
            catch (Exception)
            {
                return("Error database error");
            }
        }

        else
        {
            docPath = null;
        }

        if (string.IsNullOrEmpty(InventoryHeader))

        {
            InventoryHeader = null;
        }


        using (SqlConnection connection = new SqlConnection(connStr))
        {
            try
            {
                string     storedProc = "bizInventory_updateHeader";
                SqlCommand cmd        = new SqlCommand(storedProc, connection);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.VarChar, 50));
                cmd.Parameters.Add(new SqlParameter("@docPath", SqlDbType.VarChar, 1000));
                cmd.Parameters.Add(new SqlParameter("@inventoryHeader", SqlDbType.VarChar, 100));

                cmd.Parameters["@ID"].Value = Membership.GetUser().ProviderUserKey.ToString();


                if (!string.IsNullOrEmpty(docPath))
                {
                    cmd.Parameters["@docPath"].Value = @"http://" + awsDirName + @".s3.amazonaws.com" + @"/" + docPath;
                    docPath = @"http://" + awsDirName + @".s3.amazonaws.com" + @"/" + docPath;
                }
                else
                {
                    cmd.Parameters["@docPath"].Value = docPath;
                    docPath = "Error - Null";
                }

                //System.Windows.Forms.MessageBox.Show("Header is " + InventoryHeader);
                cmd.Parameters["@inventoryHeader"].Value = InventoryHeader;
                connection.Open();
                int rtn = cmd.ExecuteNonQuery();
            }
            catch (SqlException err)
            {
                return("Error 6");
            }
            finally {
                connection.Close();
            }
        }

        // Update the bizInventoryTablewith the details; create 2 new columns on the table
        return(docPath);
    }
    public static int sendOrgImgToCloud(FileUpload htmlFilePost, string sqlVar, string picCaption)
    {
        /*
         * Orginal file Path    :   Images/orginal/UserID/filename.fileextension
         * Thumb Nail           :   Images/thumbsNails/UserID/filename.fileextension
         * GalleryFile          :   Images/gallery/UserID/filename.fileextension
         *
         *
         *
         *
         *
         */
        string connStr = WebConfigurationManager.ConnectionStrings["eastManDB"].ConnectionString;
        string thumbNailFileName;
        string galleryFileName;

        try
        {
            if (CommonFunctions.IsImage(htmlFilePost.PostedFile))
            {
                if (htmlFilePost.PostedFile.ContentLength < MaxSize)
                {
                    AmazonS3 myS3           = new com.amazonaws.s3.AmazonS3();
                    DateTime myTime         = DateTime.Now;
                    string   strMySignature = S3Helper.GetSignature(
                        mySecretAccessKeyId,
                        "PutObjectInline",
                        myTime);

                    Grant   myGrant  = new com.amazonaws.s3.Grant();
                    Grant[] myGrants = new Grant[1];
                    com.amazonaws.s3.Group myGroup = new com.amazonaws.s3.Group();
                    myGroup.URI        = "http://acs.amazonaws.com/groups/global/AllUsers";
                    myGrant.Grantee    = myGroup;
                    myGrant.Permission = Permission.READ;
                    myGrants[0]        = myGrant;

                    MetadataEntry myContentType = new MetadataEntry();
                    myContentType.Name  = "ContentType";
                    myContentType.Value = htmlFilePost.PostedFile.ContentType;

                    MetadataEntry[] myMetaData = new MetadataEntry[1];
                    myMetaData[0]       = myContentType;
                    myContentType.Value = htmlFilePost.PostedFile.ContentType;

                    string uploadFileName = @"Images/orginal/"
                                            + Membership.GetUser().ProviderUserKey.ToString()
                                            + @"/" +
                                            sqlVar + System.IO.Path.GetExtension(htmlFilePost.PostedFile.FileName);

                    thumbNailFileName = @"Images/thumbNails/"
                                        + Membership.GetUser().ProviderUserKey.ToString()
                                        + @"/" + sqlVar + System.IO.Path.GetExtension(htmlFilePost.PostedFile.FileName);

                    galleryFileName = @"Images/gallery/"
                                      + Membership.GetUser().ProviderUserKey.ToString()
                                      + @"/" + sqlVar + System.IO.Path.GetExtension(htmlFilePost.PostedFile.FileName);

                    PutObjectResult myResult =
                        myS3.PutObjectInline(
                            awsDirName,
                            uploadFileName,
                            myMetaData,
                            htmlFilePost.FileBytes,
                            htmlFilePost.FileBytes.Length,
                            myGrants,
                            StorageClass.STANDARD,
                            true,
                            myAWSAccessKeyId,
                            S3Helper.GetTimeStamp(myTime),
                            true,
                            strMySignature, null
                            );

                    using (System.Drawing.Image image = System.Drawing.Image.FromStream(htmlFilePost.FileContent))
                        using (Bitmap bitmap = new Bitmap(image, 75, 75))
                        {
                            byte[] bytes = (byte[])System.ComponentModel.TypeDescriptor.GetConverter(bitmap).ConvertTo(bitmap, typeof(byte[]));

                            PutObjectResult thumbNailFile =
                                myS3.PutObjectInline(
                                    awsDirName,
                                    thumbNailFileName,
                                    myMetaData,
                                    bytes,
                                    bytes.Length,
                                    myGrants,
                                    StorageClass.STANDARD,
                                    true,
                                    myAWSAccessKeyId,
                                    S3Helper.GetTimeStamp(myTime),
                                    true,
                                    strMySignature, null
                                    );
                        }
                    //    byte[] bytes = (byte[])System.ComponentModel.TypeDescriptor.GetConverter(bitmap).ConvertTo(bitmap, typeof(byte[]));
                    using (System.Drawing.Image image = System.Drawing.Image.FromStream(htmlFilePost.FileContent))
                        using (Bitmap bitmapGallery = new Bitmap(image, 300, 300))
                        {
                            byte[] bytesGallery = (byte[])System.ComponentModel.TypeDescriptor.GetConverter(bitmapGallery).ConvertTo(bitmapGallery, typeof(byte[]));

                            PutObjectResult galleryFile =
                                myS3.PutObjectInline(
                                    awsDirName,
                                    galleryFileName,
                                    myMetaData,
                                    bytesGallery,
                                    bytesGallery.Length,
                                    myGrants,
                                    StorageClass.STANDARD,
                                    true,
                                    myAWSAccessKeyId,
                                    S3Helper.GetTimeStamp(myTime),
                                    true,
                                    strMySignature, null
                                    );
                        }

                    string        storedProc = "bizPicDtls_Update_" + sqlVar;
                    SqlConnection con        = new SqlConnection(connStr);
                    SqlCommand    cmd        = new SqlCommand(storedProc, con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add(new SqlParameter("@imgPath", SqlDbType.VarChar, 1000));
                    cmd.Parameters.Add(new SqlParameter("@imgThumbNailPath", SqlDbType.VarChar, 1000));
                    cmd.Parameters.Add(new SqlParameter("@imggalleryPath", SqlDbType.VarChar, 1000));
                    cmd.Parameters.Add(new SqlParameter("@imgCaption", SqlDbType.VarChar, 100));
                    cmd.Parameters.Add(new SqlParameter("@imgID", SqlDbType.VarChar, 50));

                    if (sqlVar == "profileImg")
                    {
                        cmd.Parameters.Add(new SqlParameter("@IsABiz", SqlDbType.Bit));
                        if (HttpContext.Current.User.IsInRole("bizOwner"))
                        {
                            cmd.Parameters["@IsABiz"].Value = 1;
                        }
                        else
                        {
                            cmd.Parameters["@IsABiz"].Value = 0;
                        }
                    }


                    cmd.Parameters["@imgPath"].Value          = @"http://" + awsDirName + @".s3.amazonaws.com" + @"/" + uploadFileName;
                    cmd.Parameters["@imgThumbNailPath"].Value = @"http://" + awsDirName + @".s3.amazonaws.com" + @"/" + thumbNailFileName;
                    cmd.Parameters["@imggalleryPath"].Value   = @"http://" + awsDirName + @".s3.amazonaws.com" + @"/" + galleryFileName;
                    if (!string.IsNullOrEmpty(picCaption))
                    {
                        cmd.Parameters["@imgCaption"].Value = picCaption;
                    }
                    else
                    {
                        cmd.Parameters["@imgCaption"].Value = DBNull.Value;
                    }
                    cmd.Parameters["@imgID"].Value = Membership.GetUser().ProviderUserKey.ToString();



                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                    }

                    catch (SqlException err)
                    {
                        System.Windows.Forms.MessageBox.Show(err.Message);
                        return(12);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
                else
                {
                    return(2);
                }
            }
            else
            {
                return(1);
            }
        }
        catch (Exception err)
        {
            // System.Windows.Forms.MessageBox.Show(err.Message);
            return(10);
        }
        finally
        {
        }
        return(0);
    }