Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3816

Arrays are resetted after calling SendSync with URLConnection

$
0
0

Hello!

I need some help as I’m truly unable to understand what’s going on here… I have a Thread sub class that saves images stored in an array and uploads them to a CDN giving them a proper name.

In a window I have a property, Self.tUploadImages that represents the Thread (cImageProcessor), once instantiated, I simply pass the array of the images with the corresponding names (let’s say 3 images and 3 names), to two properties defined inside the Thread sub class and then run it.

Self.tUploadImages = New cImageProcessor
Self.tUploadImages.images = imagesArray
Self.tUploadImages.names = namesArray
Self.tUploadImages.Start

Here’s the code in the Run event of the Thread, problem is that after the line “Call u.SendSync etc…” both images and names arrays inside the thread are reset to -1. Their values simply disappear! So first run of the For loop is ok, the next I get an OutOfBound Exeception.

I don’t really know why this is happening, can someone help?

macOS 14.6.1 and Xojo 2024R2.1

Var lastindex As Integer = images.LastIndex
Var u As URLConnection
Var f As FolderItem

For i As Integer = 0 To lastindex
  
  // ###########################
  // ### SAVE THE IMAGE TO A FILE
  // ###########################
  
  f = SpecialFolder.Temporary.Child(names(i))
  images(i).Save(f, Picture.Formats.JPEG, 90)
  
  // ################################
  // ### UPLOAD THE IMAGE ON THE CDN
  // ################################
  
  u = New URLConnection
  u.RequestHeader("Content-Type") = "image/jpeg"
  u.RequestHeader("Content-Length") = f.Length.ToString
  u.SetRequestContent(f.ImageToString, "image/jpeg")
  
  Call u.SendSync("PUT", "https://cdn.myserver.com/"+f.Name, 100)
  
  // ######################
  // ### DELETE IMAGE FILE
  // ######################
  
  f.Remove

Next

ImageToString is a simple function that extends a FolderItem

Public Function ImageToString(Extends f As FolderItem) As String
  Var t As TextInputStream = TextInputStream.Open(f)
  Var s As String = t.ReadAll()
  t.Close
  
  Return s
End Function

Thanks!

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 3816

Trending Articles