Amazon s3 POST (HTTPSocket ) and DropBox

Hi,

I have program that uploads images to S3 by using HTTPSocket. I build a form with the image and some other data and submit to s3. Part of the code is given below.


    Dim rawData As String
    Dim picFile As FolderItem = filesToUpload(counter)
    
    if picFile = nil then Return
    Dim bStream As BinaryStream = picFile.OpenAsBinaryFile()
    if bStream = nil then Return
    rawData = bStream.Read(picFile.Length)
    bStream.Close
    newName1 = ""

    url = "http://xxxxx.cloudfront.net/"
    Dim fieldLocation,fieldLocationkey,sign,policystr,createFolder,fileTypeExts,acl,access,filename As String
    accountNo = Uppercase(accountNo)
    fieldLocation = "Filename"
    fieldLocationkey = "key"
    
      
    
    if WindowManager.wu <> nil then
      data = data + "Content-Disposition: form-data; name="+""""+fieldLocationkey+""""+nl + nl + keystr + nl
      
    else
      data = data + "Content-Disposition: form-data; name="+""""+fieldLocationkey+""""+nl + nl + keystr + nl
      
    end
    data = data + "--" + boundary + nl
    
    
    if WindowManager.wu <> nil then
      data = data + "Content-Disposition: form-data; name="+""""+sign+""""+nl + nl + WindowManager.wu.signature + nl
      
    else
      data = data + "Content-Disposition: form-data; name="+""""+sign+""""+nl + nl + signature + nl
      
    end
    data = data + "--" + boundary + nl
    
    if WindowManager.wu <> nil then
      data = data + "Content-Disposition: form-data; name="+""""+policystr+""""+nl + nl + WindowManager.wu.policy + nl
      
    else
      data = data + "Content-Disposition: form-data; name="+""""+policystr+""""+nl + nl + policy + nl
      
    end
    data = data + "--" + boundary + nl
    
    data = data + "Content-Disposition: form-data; name="+""""+createFolder+""""+nl + nl + "false" + nl
    data = data + "--" + boundary + nl
    
    data = data + "Content-Disposition: form-data; name="+""""+fileTypeExts+""""+nl + nl + "*.jpg;*.jpeg;*.tiff;*.tif;" + nl
    data = data + "--" + boundary + nl
    
    data = data + "Content-Disposition: form-data; name="+""""+acl+""""+nl + nl + "private" + nl
    data = data + "--" + boundary + nl
    
    data = data + "Content-Disposition: form-data; name="+""""+access+""""+nl + nl + "xyz123" + nl
    data = data + "--" + boundary + nl
    
    // Next comes the actual file itself, with headers indicating what type it is
    // and what content type we&apos;re using (raw binary in this case)
    
  
    // Now our closing boundary marker, and our data is ready to send
    data = data + "--" + boundary + "--" + nl + nl
    
    if HTTPSocketUploadImage = nil then Return
    
    
    Dim form as Dictionary
    form = New Dictionary
    
    HTTPSocketUploadImage.SetPostContent data, "multipart/form-data, boundary=" + boundary
    
    
    Dim dateStr As String
    Dim tempDate As Date = picFile.CreationDate
    dateStr = EncodeURLComponent(str(tempDate.Day) + "/"+str(tempDate.Month) + "/"+str(tempDate.Year)+" "+str(tempDate.Hour)+":"+str(tempDate.Minute)+":"+str(tempDate.Second))
    
    HTTPSocketUploadImage.Post(url)

Obviously I have removed part of the code to simplify and for security.

This code works perfectly fine but recently we noticed that the uploads do not happen if the DropBox is running in the background (sometimes). The upload just don’t start and instead it stalls and nothing happens. Has anyone come across a same situation while uploading to S3?

  • I was under the suspicion that both DropBox and my code was trying use the same port and DropBox is blocking my program form uploading. If it is the case

  • Do you know how to see which port is being used by this program in a Mac? I did use this in my terminal

lsof -i | grep LISTEN

even though dropbox was there I could not find any reference to my program

Dropbox   2149 isuru   43u  IPv4 0x783b2e8f3ed22963      0t0  TCP localhost:17600 (LISTEN)
Dropbox   2149 isuru   52u  IPv4 0x783b2e8f3eb71963      0t0  TCP localhost:25961 (LISTEN)
Dropbox   2149 isuru   61u  IPv4 0x783b2e8f3ed2217b      0t0  TCP localhost:17603 (LISTEN)
Dropbox   2149 isuru   62u  IPv4 0x783b2e8f3ed25963      0t0  TCP *:17500 (LISTEN)

I know this is a long shot. However if you have any suggestions, help or can point me in to the right direction, I would greatly appreciate it.

Thanks,
Isuru

[quote=210183:@Isuru Palliyaguru]

  • I was under the suspicion that both DropBox and my code was trying use the same port and DropBox is blocking my program form uploading. If it is the case

  • Do you know how to see which port is being used by this program in a Mac? I did use this in my terminal

lsof -i | grep LISTEN

even though dropbox was there I could not find any reference to my program

Dropbox   2149 isuru   43u  IPv4 0x783b2e8f3ed22963      0t0  TCP localhost:17600 (LISTEN)
Dropbox   2149 isuru   52u  IPv4 0x783b2e8f3eb71963      0t0  TCP localhost:25961 (LISTEN)
Dropbox   2149 isuru   61u  IPv4 0x783b2e8f3ed2217b      0t0  TCP localhost:17603 (LISTEN)
Dropbox   2149 isuru   62u  IPv4 0x783b2e8f3ed25963      0t0  TCP *:17500 (LISTEN)

I know this is a long shot. However if you have any suggestions, help or can point me in to the right direction, I would greatly appreciate it.

Thanks,
Isuru[/quote]

You need to get the process ID for your app first. Run ps -e and look for your app. Or, get a cleaner response with

ps -Ac -o pid,comm | awk '/^ *[0-9]+ YourAppName$/ {print $1}

Now you have the PID of your app, you can run lsof like this (obviously exchanging PID for the PID of your app):

lsof -i -n -P | grep PID