Monday, December 21, 2020

Apple M1 Silicon + Django = weird results

Folks,

I'm using django for an online gallery application, and I've seen some weird results since switching over to the M1 Mac Mini.
(Please note, I am running it under Rosetta / Intel Translation, since pillow doesn't seem to build under M1 native).

So this could be a quirk of Rosetta, Django, or some combination of these.

I don't think so, but it could be.

So What is happening?  

I never saw this under my 2013 intel iMac, but now under M1 (even under Rosetta 2 / Intel translation) I am receiving a damaged / altered download file roughly 6 out of 8 or 9 times (~25-33% successful).  

Just retrying the download will eventually be successful.  

This isn't Pillow related, since the file is just being downloaded directly (no thumbnails or alterations to the file is occurring).

Does anyone have a suggestion on what to do at this time?  I'm uncertain on where to start to dig.  Although removing ranged_response, might be a starting point…

URLs:
    path("download/<uuid:d_uuid>", frontend.views.new_download, name="downloads"),
    path('thumbnails/<uuid:t_url_name>', frontend.views.thumbnails, name="raw thumbnails"),


First, I am using these function for all graphics and/or file(s) being sent:

def new_download(request, d_uuid=None):
    page = request.GET.get('page', None)
    if page is None:
        download = index_data.objects.filter(uuid=d_uuid,
                                             ignore=False,
                                             delete_pending=False)[0]
    else:
        print ("Attempting to find page %s in archive" % page)
    print("\tDownloading - %s, %s" % (download.fqpndirectory.lower(),
                                      download.name))
    return respond_as_inline(request,
                                 "%s%s%s" % (
                                     configdata["locations"]["albums_path"],
                                     os.sep,
                                     download.fqpndirectory),
                                 download.name)


def respond_as_inline(request, file_path, original_filename, ranged=False):
    filename = os.path.join(file_path, original_filename)
    if os.path.exists(filename):
        mtype, encoding = mimetypes.guess_type(original_filename)
        if mtype is None:
            mtype = 'application/octet-stream'
        response = RangedFileResponse(request, file=open(filename, 'rb'), as_attachment=False, filename=os.path.basename(filename))
        response["Content-Type"] = mtype
        return response
    raise Http404


No comments:

Post a Comment