Networking with URLSession · Uploading Data |

This is a companion discussion topic for the original entry at

Hi @bdmoakley,

Out of curiosity, what’s the litmus test to decide whether to use the shared singleton vs a full blown session object when prepping for a URLSession operation? Also, in this case we set the delegate up on the main operation queue. When might we want to use a different queue, and why?


Deciding to use a singleton vs. a full session is really a use case decision (in my opinion). If was doing a simple request where I needed just to make a request, then I’d use the singleton but anything more than that, I’d use an object. That said, I know developers who refuse to use singletons unless they actually have to use it.

As for different queues, you may want to set up dependencies, For instance, you may want to download some information, process it, then upload it to a different service. Doing this in a background queue won’t affect the user interface at all. I hope that helps!

1 Like

It does indeed! Much obliged!

Why is it necessary to deal with Python? Is it because Flask needs it? Or would every upload need this Python step?

I found this to be the easiest way to setup a server to show uploading. I didn’t want to provide too many steps where you’d be focusing on the server setup vs. the actual uploading. You can use any server technology you want.

So in conclusion the Python steps are necessary because Flask is set up to use it? So not every server needs a bit of Python work? Or do I have it wrong? Thx for your answer.

Hey there, Python is absolutely not necessary to create a server. I only used Python to create a Flask server because it took very little code to do. You could have just as easily used a server written in Swift or C# or even plain old C. SO to answer your question, python is not necessary.

Hello Mr. Moakley, I get this error in the terminal;

(vflask) Sedats-MacBook-Pro:~ sedatonurduzova$ flask run

  • Serving Flask app “”
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
    Usage: flask run [OPTIONS]

Error: Could not import “upload”.
(vflask) Sedats-MacBook-Pro:~ sedatonurduzova$

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi ,

I have the same issue as Onursd,

Error: Could not import “upload”.

if you could help !

To run that file in Flask you will first need to navigate to the same folder.
In the video, Brian has the python script on his Desktop and also in the terminal window he’s in his Desktop (the current opened folder is written before the username in the terminal window).
If you have the file somewhere else, you will need to navigate to the enclosing folder by using the command “cd” followed by the full path. Or alternatively you can also open the folder in finder and drag the folder inside terminal window.

@henc Thank you for sharing your solution - much appreciated! :]

1 Like

I have a working php server with the ability to upload files (everything is fine when I load the same image from an HTML form).
But when I try your example, I always have an empty $ _POST array and an empty $ _FILES array on my server.

I tried this example (Upload image to server using URLSessionUploadTask) and everything worked fine!
Please tell me, can I get the same result with your code and php server?
Thank you!

Sorry for my language :slight_smile:

If you are getting an empty $_POST array, then it sounds like the image isn’t being uploaded. Did you look at any errors during the upload process? That’s the best place to start. Also, have you tried uploading an image by way of an external script?

There are lots of places where this can bug out. You’ll have to do a bit of investigating to determine the location of the breakdown.

Hi could you help with this please I’m a bit stuck hereScreenshot 2020-09-06 at 22.02.26

Hi I’m having the same issue, and I tried your solution and I still get that outcome.

Do I need to follow that link first and after follow your steps? I’m a bit confused …I installed python in my terminal, I have files on my desktop but the terminal still couldn’t import “upload”. I also double checked if I installed python 3 which is done, but I don’t understand why is not uploading this file.(been on this issue like more than 2 hours)Screenshot 2020-09-07 at 00.43.16

Could someone help out with this issue???

Hi George, would you copy and paste the contents of Sounds like something may be going wrong there.