Repository: openwisp/openwisp-firmware-upgrader (language: python)

Issue:
Firmware filename is limited to 100 characters
Hi, I'm compiling my own openWRT firmware for a Xiaomi Mi Router 4a Gigabyte edition, but the generated firmware can't be upload to the openWISP server because the limit of firmware filename: `ramips-mt7621-xiaomi_mi-router-4a-gigabit-squashfs-sysupgrade.bin`

![image](https://github.com/openwisp/openwisp-firmware-upgrader/assets/119055741/6e3c6751-4a76-45e4-a3a3-b49684281098)

There are some config to change this or this is a simple limit of model on django migrations?

I'm using the imagebuilder ansible playbook and tested directly on the site too.



Discussion / hints:
I think it may be a deafult limit as I don't see an explicit one defined in the code: https://github.com/openwisp/openwisp-firmware-upgrader/blob/master/openwisp_firmware_upgrader/base/models.py#L209-L214

As a temporary workaround you should be able to reduce the file name and select the image type manually.
Hii I would like to work on this issue Please assign me this issue

> I think it may be a deafult limit as I don't see an explicit one defined in the code: https://github.com/openwisp/openwisp-firmware-upgrader/blob/master/openwisp_firmware_upgrader/base/models.py#L209-L214
> 
> As a temporary workaround you should be able to reduce the file name and select the image type manually.

Yup, the Django FileField default is 100 characters

Fix patch:
diff --git a/openwisp_firmware_upgrader/base/models.py b/openwisp_firmware_upgrader/base/models.py
index 0b33d565..e9091b31 100644
--- a/openwisp_firmware_upgrader/base/models.py
+++ b/openwisp_firmware_upgrader/base/models.py
@@ -211,6 +211,7 @@ class AbstractFirmwareImage(TimeStampedEditableModel):
         upload_to=get_build_directory,
         max_file_size=app_settings.MAX_FILE_SIZE,
         storage=app_settings.PRIVATE_STORAGE_INSTANCE,
+        max_length=255,
     )
     type = models.CharField(
         blank=True,
diff --git a/openwisp_firmware_upgrader/migrations/0010_alter_firmwareimage_file.py b/openwisp_firmware_upgrader/migrations/0010_alter_firmwareimage_file.py
new file mode 100644
index 00000000..b78a68c1
--- /dev/null
+++ b/openwisp_firmware_upgrader/migrations/0010_alter_firmwareimage_file.py
@@ -0,0 +1,30 @@
+# Generated by Django 4.2.13 on 2024-05-30 07:38
+
+from urllib.parse import urljoin
+from ..settings import FIRMWARE_API_BASEURL, IMAGE_URL_PATH
+from django.db import migrations
+import openwisp_firmware_upgrader.base.models
+import private_storage.fields
+import private_storage.storage.files
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("firmware_upgrader", "0009_upgrade_options"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="firmwareimage",
+            name="file",
+            field=private_storage.fields.PrivateFileField(
+                max_length=255,
+                storage=private_storage.storage.files.PrivateFileSystemStorage(
+                    base_url=urljoin(FIRMWARE_API_BASEURL, IMAGE_URL_PATH),
+                ),
+                upload_to=openwisp_firmware_upgrader.base.models.get_build_directory,
+                verbose_name="File",
+            ),
+        ),
+    ]


Test patch:
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0004_alter_firmwareimage_file.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0004_alter_firmwareimage_file.py
new file mode 100644
index 00000000..b51152dc
--- /dev/null
+++ b/tests/openwisp2/sample_firmware_upgrader/migrations/0004_alter_firmwareimage_file.py
@@ -0,0 +1,30 @@
+# Generated by Django 4.2.13 on 2024-05-30 07:51
+
+from urllib.parse import urljoin
+from openwisp_firmware_upgrader.settings import FIRMWARE_API_BASEURL, IMAGE_URL_PATH
+from django.db import migrations
+import openwisp_firmware_upgrader.base.models
+import private_storage.fields
+import private_storage.storage.files
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("sample_firmware_upgrader", "0003_create_device_firmware"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="firmwareimage",
+            name="file",
+            field=private_storage.fields.PrivateFileField(
+                max_length=255,
+                storage=private_storage.storage.files.PrivateFileSystemStorage(
+                    base_url=urljoin(FIRMWARE_API_BASEURL, IMAGE_URL_PATH),
+                ),
+                upload_to=openwisp_firmware_upgrader.base.models.get_build_directory,
+                verbose_name="File",
+            ),
+        ),
+    ]