当前位置: 首页>>代码示例>>C#>>正文


C# AmazonS3.UploadFile方法代码示例

本文整理汇总了C#中AmazonS3.UploadFile方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3.UploadFile方法的具体用法?C# AmazonS3.UploadFile怎么用?C# AmazonS3.UploadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AmazonS3的用法示例。


在下文中一共展示了AmazonS3.UploadFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadScreenSplashButton_Click

    protected void UploadScreenSplashButton_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;

        if (UploadScreenSplash.UploadedFiles.Count > 0)
        {
            repeaterResultsScreenSplash.DataSource = UploadScreenSplash.UploadedFiles;
            repeaterResultsScreenSplash.DataBind();
            repeaterResultsScreenSplash.Visible = true;
            string targetFolder = Server.MapPath(UploadScreenSplash.TargetFolder);
            foreach (UploadedFile file in UploadScreenSplash.UploadedFiles)
            {
                string name = file.GetName();
                string file_path = targetFolder + @"\" + name;
                if (System.IO.File.Exists(file_path))
                {
                    byte[] image_data = File.ReadAllBytes(file_path);
                    ImageConverter ic = new ImageConverter();
                    System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(image_data);
                    Bitmap bitmap = new Bitmap(img);
                    int expected_width = Constants.IPHONE_DISPLAY_WIDTH;
                    int expected_height = Constants.IPHONE_SCROLL_HEIGHT;
                    switch (State["SelectedDeviceType"].ToString())
                    {
                        case Constants.IPAD:
                           expected_width = Constants.IPAD_DISPLAY_WIDTH;
                           expected_height = Constants.IPAD_SCROLL_HEIGHT;
                            break;
                        case Constants.ANDROID_TABLET:
                            expected_width = Constants.ANDROID_TABLET_DISPLAY_WIDTH;
                            expected_height = Constants.ANDROID_TABLET_SCROLL_HEIGHT;
                            break;
                        case Constants.IPHONE:
                            expected_width = Constants.IPHONE_DISPLAY_WIDTH;
                            expected_height = Constants.IPHONE_SCROLL_HEIGHT;
                           break;
                        case Constants.ANDROID_PHONE:
                           expected_width = Constants.ANDROID_PHONE_DISPLAY_WIDTH;
                           expected_height = Constants.ANDROID_PHONE_SCROLL_HEIGHT;
                            break;
                    }
                    if (bitmap.Width != expected_width || bitmap.Height != expected_height)
                    {
                        SplashUploadMessage.Text = "The image '" + name + "' is not the right size";
                        return;
                    }

                    AmazonS3 s3 = new AmazonS3();
                    string file_name = name.Replace(" ", "_");
                    string url = s3.UploadFile(State, file_name, file_path);
                    if (!url.StartsWith("http"))
                        return;

                    if (File.Exists(file_path))
                        File.Delete(file_path);

                    util.SetApplicationSplashImage(State,  State["ApplicationID"].ToString(), url);

                    ScreenSplashButton.Visible = true;
                    DeleteSplashImage.Visible = true;

                }
            }
        }
        else
        {
            repeaterResultsScreenSplash.Visible = false;
            SplashUploadMessage.Text = "Browse for a file";
        }
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:72,代码来源:PublishingFormWebApps.aspx.cs

示例2: UploadButton_Click

    protected void UploadButton_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        if (UploadMessage.Text.Length > 0)
            return;

        int width =  Convert.ToInt32(Width.Text);
        int height = Convert.ToInt32(Height.Text);

        if (UploadBackground.UploadedFiles.Count > 0)
        {
             string targetFolder = Server.MapPath(UploadBackground.TargetFolder);
            foreach (UploadedFile file in UploadBackground.UploadedFiles)
            {
                string name = file.GetName();
                if (!name.EndsWith(".png") && !name.EndsWith(".jpg") && !name.EndsWith(".gif"))
                {
                    UploadMessage.Text = "The image format for '" + name + "' is not allowed";
                    return;
                }
                string file_path = targetFolder + @"\" + name;
                if (System.IO.File.Exists(file_path))
                {
                    byte[] image_data = File.ReadAllBytes(file_path);
                    ImageConverter ic = new ImageConverter();
                    System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(image_data);
                    Bitmap bitmap = new Bitmap(img);
                    if (bitmap.Width != width || bitmap.Height != height)
                    {
                        UploadMessage.Text = "The image '" + name + "' is not " + Width.Text + " X " + Height.Text;
                        return;
                    }

                    string file_name =  util.FilterWebFileName(name);
                    string save_file_path =  HttpRuntime.Cache["TempFilesPath"].ToString() + State["Username"].ToString() + "." + file_name;

                    try
                    {
                        if (File.Exists(save_file_path))
                            File.Delete(save_file_path);

                        File.WriteAllBytes(save_file_path, image_data);
                        File.Delete(file_path);
                    }
                    catch
                    {
                        //Trying to overwrite the same file
                    }

                    AmazonS3 s3 = new AmazonS3();
                    string url = s3.UploadFile(State, file_name, save_file_path);
                    if (!url.StartsWith("http"))
                        return ;

                    if (File.Exists(save_file_path))
                        File.Delete(save_file_path);

                    ImageSource.Text = url;
                    UploadMessage.Text = "Upload Successful. Click Close.";
                }
            }
        }
        else
        {
            UploadMessage.Text = "Browse for a file";
        }
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:70,代码来源:UploadBackgroundImage.aspx.cs

示例3: ConvertToImageLink


//.........这里部分代码省略.........
                {
                    start = end + 6;
                    quote_type = "encoded";
                }
                else if (sb_html[end] == '"')
                {
                    start = end + 1;
                    quote_type = "quote";
                }
                else
                    start = end;

                if (sb_html.ToString().Substring(start, 4) != "http")
                {
                    sb_html.Insert(start,  HttpRuntime.Cache["PublicViziAppsUrl"].ToString() + "/");
                }
                //get image url
                switch (quote_type)
                {
                    case "none":
                        end = sb_html.ToString().IndexOf(")", start);
                        break;
                    case "encoded":
                        end = sb_html.ToString().IndexOf(""", start);
                        break;
                    case "quote":
                        end = sb_html.ToString().IndexOf("\"", start);
                        break;
                }

                string image_url = sb_html.ToString().Substring(start, end - start);
                start = end + 1;
                end = sb_html.ToString().IndexOf(">", start);
                start = end + 1;
                sb_html.Insert(start, " <img src=\"" + image_url + "\"/>");
                sb_html.Insert(end, " style=\"overflow:hidden\" ");
            }
        } while (end >= 0);

        Util util = new Util();
        string file_name =  State["SelectedApp"].ToString() + "." + page_name + ".jpg";
        file_name = file_name.Replace(" ","_");
        string save_file_path =  HttpRuntime.Cache["TempFilesPath"].ToString() + State["Username"].ToString() + "." + file_name;

        int browserWidth = Constants.IPHONE_DISPLAY_WIDTH;
        int browserHeight = Convert.ToInt32(Constants.IPHONE_SCROLL_HEIGHT_S);
        int thumbnailWidth = browserWidth;
        int thumbnailHeight = browserHeight;
        if (State["SelectedDeviceType"].ToString() == Constants.IPAD)
        {
            browserWidth = Constants.IPAD_DISPLAY_WIDTH;
            browserHeight = Constants.IPAD_DISPLAY_HEIGHT;
            thumbnailWidth = browserWidth;
            thumbnailHeight = browserHeight;
        }
        else if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_TABLET)
        {
            browserWidth = Constants.ANDROID_TABLET_DISPLAY_WIDTH;
            browserHeight = Constants.ANDROID_TABLET_DISPLAY_HEIGHT;
            thumbnailWidth = browserWidth;
            thumbnailHeight = browserHeight;
        }
        string whole_html =  HttpRuntime.Cache["CanvasHtml"].ToString().Replace("<REPLACE>", sb_html.ToString());

        string temp_store_path =  HttpRuntime.Cache["TempFilesPath"].ToString() + "canvas.htm";
        File.WriteAllText(temp_store_path, whole_html.Replace("iframe","div"));

        string siteurl = "file:///" + temp_store_path;
        System.Drawing.Image img =
                (System.Drawing.Image)PAB.WebControls.WebSiteThumbnail.GetSiteThumbnail(siteurl,
                          browserWidth, browserHeight, thumbnailWidth, thumbnailHeight, save_file_path);

        if (!File.Exists(save_file_path))
            return null;

        try
        {
            if (File.Exists(temp_store_path))
                File.Delete(temp_store_path);
        }
        catch{
            //file access issues
        };

        string url = null;
        try{
            AmazonS3 s3 = new AmazonS3();
            url = s3.UploadFile(State, file_name, save_file_path);
            if (!url.StartsWith("http"))
                return null;

            if (File.Exists(save_file_path))
                File.Delete(save_file_path);
        }
        catch{
            //file access issues
        };

        return url;
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:101,代码来源:HtmlToImage.cs

示例4: UploadButton_Click

    protected void UploadButton_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        if (UploadBackground.UploadedFiles.Count > 0)
        {
            string targetFolder = Server.MapPath(UploadBackground.TargetFolder);
            foreach (UploadedFile file in UploadBackground.UploadedFiles)
            {
                string name = file.GetName();
                string file_path = targetFolder + @"\" + name;
                if (file_path.Contains(".wav") && file_path.Contains(".mp3"))
                {
                    UploadMessage.Text = name + "' is not a .mp3 or .wav file";
                    return;
                }

                if (System.IO.File.Exists(file_path))
                {
                    byte[] audio_data = File.ReadAllBytes(file_path);

                    string file_name =  name.Replace(" ", "_").Replace("%20", "_");
                    string save_file_path =  HttpRuntime.Cache["TempFilesPath"].ToString() + State["Username"].ToString() + "." + file_name;

                    try
                    {
                        if (File.Exists(save_file_path))
                            File.Delete(save_file_path);

                        File.WriteAllBytes(save_file_path, audio_data);
                        File.Delete(file_path);
                    }
                    catch
                    {
                        //Trying to overwrite the same file
                    }

                    AmazonS3 s3 = new AmazonS3();
                    string url = s3.UploadFile(State, file_name, save_file_path);
                    if (!url.StartsWith("http"))
                        return;

                    try
                    {
                        if (File.Exists(save_file_path))
                            File.Delete(save_file_path);
                    }
                    catch (Exception ex)
                    {
                    }

                    ImageSource.Value = url;
                    UploadMessage.Text = "Upload Successful. Click Close.";
                }
            }
        }
        else
        {
            UploadMessage.Text = "Browse for a file";
        }
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:63,代码来源:UploadAudio.aspx.cs

示例5: SetApplicationLargeIcon

    public void SetApplicationLargeIcon(Hashtable State, string application_id, Bitmap bitmap, string file_name, string file_path)
    {
        DeleteLargeIcon(State, application_id);

        AmazonS3 s3 = new AmazonS3();

        string url = s3.UploadFile(State, file_name, file_path);
        if (!url.StartsWith("http"))
            throw new Exception("Error in SetApplicationLargeIcon: s3.UploadFile failed.");

        if (File.Exists(file_path))
            File.Delete(file_path);

        string[] icon_sizes = { "114", "72", "58", "57", "48", "36", "29" };

        DB db = new DB();
        StringBuilder b_sql = new StringBuilder("INSERT INTO branding_images SET ");
        b_sql.Append("branding_image_id='" + Guid.NewGuid().ToString() + "'");
        b_sql.Append(",application_id='" + application_id + "'");
        b_sql.Append(",width=512,height=512,type='icon'");
        b_sql.Append(",url='" + url + "'");
        db.ViziAppsExecuteNonQuery(State, b_sql.ToString());

        //do all the other sizes
        foreach (string icon_size in icon_sizes)
        {
            int size = Convert.ToInt32(icon_size);
            Bitmap resized_bitmap = (Bitmap)ResizeImage(bitmap, new Size(size, size));
            resized_bitmap.Save(file_path);
            url = s3.UploadFile(State, file_name.Insert(file_name.Length - 4, "_" + icon_size), file_path);
            if (!url.StartsWith("http"))
                throw new Exception("Error in SetApplicationLargeIcon: s3.UploadFile failed.");

            if (File.Exists(file_path))
                File.Delete(file_path);

            b_sql = new StringBuilder("INSERT INTO branding_images SET ");
            b_sql.Append("branding_image_id='" + Guid.NewGuid().ToString() + "'");
            b_sql.Append(",application_id='" + application_id + "'");
            b_sql.Append(",width=" + icon_size + ",height=" + icon_size + ",type='icon'");
            b_sql.Append(",url='" + url + "'");
            db.ViziAppsExecuteNonQuery(State, b_sql.ToString());
        }
        db.CloseViziAppsDatabase(State);
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:45,代码来源:Util.cs

示例6: UploadScreenSplashButton_Click

    protected void UploadScreenSplashButton_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        if (UploadScreenSplash.UploadedFiles.Count > 0)
        {
            repeaterResultsScreenSplash.DataSource = UploadScreenSplash.UploadedFiles;
            repeaterResultsScreenSplash.DataBind();
            repeaterResultsScreenSplash.Visible = true;
            string targetFolder = Server.MapPath(UploadScreenSplash.TargetFolder);
            foreach (UploadedFile file in UploadScreenSplash.UploadedFiles)
            {
                string name = file.GetName();
                if (!name.ToLower().EndsWith(".jpg"))
                {
                    SplashUploadMessage.Text = "File must be .jpg file";
                    return;
                }
                string file_path = targetFolder + @"\" + name;
                if (System.IO.File.Exists(file_path))
                {
                    byte[] image_data = File.ReadAllBytes(file_path);
                    ImageConverter ic = new ImageConverter();
                    System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(image_data);
                    Bitmap bitmap = new Bitmap(img);
                    if (bitmap.Width != 320 || bitmap.Height != 460)
                    {
                        SplashUploadMessage.Text = "The image '" + name + "' is not 320 X 460";
                        return;
                    }

                    AmazonS3 s3 = new AmazonS3();
                    string file_name = name.Replace(" ", "_");
                    string url = s3.UploadFile(State, file_name, file_path);
                    if (!url.StartsWith("http"))
                        return;

                    if (File.Exists(file_path))
                        File.Delete(file_path);

                    util.SetApplicationSplashImage(State, State["ApplicationID"].ToString(), url);

                    ScreenSplashButton.Visible = true;
                    DeleteSplashImage.Visible = true;

                }
            }
        }
        else
        {
            repeaterResultsScreenSplash.Visible = false;
            SplashUploadMessage.Text = "Browse for a file";
        }
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:56,代码来源:PublishingForm.aspx.cs


注:本文中的AmazonS3.UploadFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。