Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7724311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:39:23+00:00 2026-06-01T04:39:23+00:00

I’m using a function that uploads an image, takes the stream and resizes it

  • 0

I’m using a function that uploads an image, takes the stream and resizes it using imageresizer.net, then uploads the stream to Amazon S3.

Now I want to take a local picture and convert it into a stream. (to resize and upload to amazonS3). Basically, how do you convert an image into a stream.

This might be a simple question, just could not find the answer anywhere.

Here is some basic code.

Public Shared Sub MoveToAmazon(strImg As String, SKU As String)
        Dim fullImg As String = "C:\ImageLocation\" & strImg
        Dim img As Image = Image.FromFile(fullImg)

        'Here Im missing the code to convert it to a stream.
        UploadImage(imgStream, SKU)  

End Sub


Public Shared Sub UploadImage(imgStream As Stream, imgName As String)

    Dim MainStream As Stream = New MemoryStream
    Dim HomeStream As Stream = New MemoryStream
    Dim SmallStream As Stream = New MemoryStream
    Dim TinyStream As Stream = New MemoryStream
    Dim MidStream As Stream = New MemoryStream
    Dim GridStream As Stream = New MemoryStream
    Dim ListStream As Stream = New MemoryStream


    Dim c As New ImageResizer.Configuration.Config

    Dim SourceImage As Bitmap = New Bitmap(imgStream)
    Dim SourceMain As Bitmap = New Bitmap(SourceImage)
    Dim SourceHome As Bitmap = New Bitmap(SourceImage)
    Dim SourceSmall As Bitmap = New Bitmap(SourceImage)
    Dim SourceTiny As Bitmap = New Bitmap(SourceImage)
    Dim SourceMid As Bitmap = New Bitmap(SourceImage)
    Dim SourceGrid As Bitmap = New Bitmap(SourceImage)
    Dim SourceList As Bitmap = New Bitmap(SourceImage)

    ImageResizer.ImageBuilder.Current.Build(SourceMain, MainStream, New ResizeSettings("width=300&height=372&scale=both&paddingWidth=40")) 'ProductPage
    ImageResizer.ImageBuilder.Current.Build(SourceHome, HomeStream, New ResizeSettings("width=112&height=147&scale=both")) 'HomePage Products
    ImageResizer.ImageBuilder.Current.Build(SourceGrid, GridStream, New ResizeSettings("width=149&height=149&scale=both")) 'Categories Grid
    ImageResizer.ImageBuilder.Current.Build(SourceList, ListStream, New ResizeSettings("width=171&height=206&scale=both")) 'Categories List
    ImageResizer.ImageBuilder.Current.Build(SourceSmall, SmallStream, New ResizeSettings("width=64&height=75&scale=both")) 'Accessories
    ImageResizer.ImageBuilder.Current.Build(SourceTiny, TinyStream, New ResizeSettings("width=82&height=82&scale=both")) 'Cart
    ImageResizer.ImageBuilder.Current.Build(SourceMid, MidStream, New ResizeSettings("width=155&height=116&scale=both")) 'CategoryMain


    AmazonUploadFile("OriginalImages/" & imgName, imgStream)
    AmazonUploadFile("MainImages/" & imgName, MainStream)
    AmazonUploadFile("HomeImages/" & imgName, HomeStream)
    AmazonUploadFile("GridImages/" & imgName, GridStream)
    AmazonUploadFile("ListImages/" & imgName, ListStream)
    AmazonUploadFile("SmallImages/" & imgName, SmallStream)
    AmazonUploadFile("TinyImages/" & imgName, TinyStream)
    AmazonUploadFile("MidImages/" & imgName, MidStream)
End Sub

Public Shared Sub AmazonUploadFile(S3Key As String, FileStream As Stream)
    Dim request As New PutObjectRequest()
    request.WithBucketName(BUCKET_NAME)
    request.WithKey(S3Key).InputStream = FileStream
    request.WithCannedACL(S3CannedACL.PublicRead)
    GetS3Client.PutObject(request)
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:39:25+00:00Added an answer on June 1, 2026 at 4:39 am

    The following code snippet should do what you want:

      Using myImage = Image.FromFile(fullImg)
        Using ms As New MemoryStream()
            myImage.Save(ms, ImageFormat.Jpeg)
            ms.Seek(0, SeekOrigin.Begin) 
            UploadImage(ms, SKU)  
        End Using
      End Using
    

    As an aside, you might find it easier to parameterize your methods and do all the work when calling them. Something like the following may make your life easier (this assumes the code you posted is code you are actually using and not a demo):

    Public Shared Sub UploadImages()
        'Call this for each image
        MoveToAmazon("C:\ImageLocation\blah.jpg", "OriginalImage", 300, 300, 0, "whatever")
    
    End Sub
    
    
    Public Shared Sub MoveToAmazon(strImg As String, targetFolder As String, height as Integer, width as Integer, padding as Integer, SKU As String)
            Dim fullImg As String = "" & strImg
            Using img = Image.FromFile(fullImg)
                'Here Im missing the code to convert it to a stream.
                Using ms As New MemoryStream()
                    Image.Save(ms, ImageFormat.Jpeg)
                    ms.Seek(0, SeekOrigin.Begin) 
                    UploadImage(ms, SKU)  
                End Using
            End Using
    End Sub
    
    
    Public Shared Sub UploadImage(imgStream As Stream, imgName As String, targetFolder As String, height as Integer, width as Integer, padding as Integer, SKU As String)
    
        Dim c As New ImageResizer.Configuration.Config
    
        ImageResizer.ImageBuilder.Current.Build(SourceMain, imgStream, New ResizeSettings("width=" & CStr(width) & "&height=" & CStr(height) & "&scale=both&paddingWidth=" & CStr(padding)) 
    
        AmazonUploadFile(targetFolder & "/" & imgName, imgStream)
    
    End Sub
    
    Public Shared Sub AmazonUploadFile(S3Key As String, FileStream As Stream)
        Dim request As New PutObjectRequest()
        request.WithBucketName(BUCKET_NAME)
        request.WithKey(S3Key).InputStream = FileStream
        request.WithCannedACL(S3CannedACL.PublicRead)
        GetS3Client.PutObject(request)
    End Sub
    
    
    Using ms As New MemoryStream()
        Image.Save(ms, ImageFormat.Jpeg)
        ms.Seek(0, SeekOrigin.Begin) 
        UploadImage(ms, SKU)  
    End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.