Share
DerekTP 5:36pm, 25 June 2020
After a lot of faffing about (largely my fault, and trying to run before I can walk!) I now have a WinForms application that can read filenames and descriptions (and other stuff!) from a spreadsheet and upload them to Flickr.
However I'm finding the uploads VERY slow (at least a minute for a small 1Mb image) and on large images the connection times out.
[UPDATED]Is there a way to asynchronously track the upload progress (i.e. how many bytes have been uploaded) to give the user some feedback during each photo upload (my app shows progress at each discrete step already). [YES - Found "OnUploadProgress" which is an event that can be handled and returns percent complete, bytes sent etc... doh! WIll try and get this working now...] Also is there a way to extend the connection lifetime to avoid timing out?
Hi there -- can you tell me how you accessed the OnUploadProgress event? I can't see it documented anywhere.
DerekTP 2 months ago
This is the relevant code in my app...

Flickr myflickr = new Flickr(ApiKey, SharedSecret); // create flickrnet Flickr instance
myflickr.OnUploadProgress += Flickr_OnUploadProgress; // add our method to the event handler

and

public void Flickr_OnUploadProgress(object sender, FlickrNet.UploadProgressEventArgs e)
{
backgroundWorker1.ReportProgress(e.ProcessPercentage); // do whatever you need to do!
}

See:
Thanks for the reply. I'm working in Python (with this library github.com/alexis-mignon/python-flickr-api) so will see if I can work out how to access that part of the API.
jim_easterbrook Posted 2 months ago. Edited by jim_easterbrook (member) 2 months ago
The way I've done this from Python (using a different Flickr API library) is to create an object that looks like a file object, but calls a callback function as each chunk of data is read. The callback function is passed the percentage of the file read so far. This will only work if the library you use accepts file objects as well as a path to a file, and reads the file object in chunks.


class FileObjWithCallback(object):
def __init__(self, fileobj, callback):
self._f = fileobj
self._callback = callback
# requests library uses 'len' attribute instead of seeking to
# end of file and back
self.len = os.fstat(self._f.fileno()).st_size

# substitute read method
def read(self, size):
if self._callback:
self._callback(self._f.tell() * 100 // self.len)
return self._f.read(size)

# delegate all other attributes to file object
def __getattr__(self, name):
return getattr(self._f, name)
jim_easterbrook 2 months ago
Sorry about the lack of indentation in my reply. The 'blockquote' markup doesn't work as I expected.
Thanks, Jim! I might switch to sybrenstuvel's flickrapi library -- it looks like the auth mechanism is a bit easier to use (and I like that it stores its upload token in ~/.flickr. This is what I'm working on, btw: https://github.com/AucklandMuseum/flickrUploader.

Thanks
Hugh
jim_easterbrook 2 months ago
I've recently moved away from the Flickrapi package and just use Python requests (and its associated packages) directly. I store oauth tokens with a Python package called "keyring". My uploader is part of this project: github.com/jim-easterbrook/Photini
Oh wow, this looks great! Thanks! Hugh.
Groups Beta