Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File uploads in v.5 #156

Open
hauptrolle opened this issue Feb 12, 2025 · 1 comment
Open

File uploads in v.5 #156

hauptrolle opened this issue Feb 12, 2025 · 1 comment

Comments

@hauptrolle
Copy link

Hey 👋 ,

is there any chance to get this fix also in v5? Seems like file uploads are broken right now.

#150

@hauptrolle
Copy link
Author

If anyone need to patch this in the old version just use this:

diff --git a/node_modules/remix-hook-form/dist/index.cjs b/node_modules/remix-hook-form/dist/index.cjs
index 58d2f94..20dcbc9 100644
--- a/node_modules/remix-hook-form/dist/index.cjs
+++ b/node_modules/remix-hook-form/dist/index.cjs
@@ -43,18 +43,23 @@ __export(src_exports, {
 module.exports = __toCommonJS(src_exports);
 
 // src/utilities/index.ts
-var tryParseJSON = (jsonString) => {
+const tryParseJSON = (value) => {
+  console.log("in tryParseJSON", value)
+  if (value instanceof File || value instanceof Blob) {
+    return value;
+  }
   try {
-    const json = JSON.parse(jsonString);
+    const json = JSON.parse(value);
+
     return json;
   } catch (e) {
-    return jsonString;
+    return value;
   }
 };
 var generateFormData = (formData, preserveStringified = false) => {
   const outputObject = {};
   for (const [key, value] of formData.entries()) {
-    const data = preserveStringified ? value : tryParseJSON(value.toString());
+    const data = preserveStringified ? value : tryParseJSON(value);
     const keyParts = key.split(".");
     let currentObject = outputObject;
     for (let i = 0; i < keyParts.length - 1; i++) {
@@ -120,7 +125,7 @@ var createFormData = (data, stringifyAll = true) => {
       }
       continue;
     }
-    if (value instanceof Array && value.length > 0 && (value[0] instanceof File || value[0] instanceof Blob)) {
+    if (value instanceof Array && value.length > 0 && value.every((item) => item instanceof File || item instanceof Blob)) {
       for (let i = 0; i < value.length; i++) {
         formData.append(key, value[i]);
       }
diff --git a/node_modules/remix-hook-form/dist/index.js b/node_modules/remix-hook-form/dist/index.js
index a4a246f..86811cf 100644
--- a/node_modules/remix-hook-form/dist/index.js
+++ b/node_modules/remix-hook-form/dist/index.js
@@ -1,16 +1,20 @@
 // src/utilities/index.ts
-var tryParseJSON = (jsonString) => {
+const tryParseJSON = (value) => {
+  if (value instanceof File || value instanceof Blob) {
+    return value;
+  }
   try {
-    const json = JSON.parse(jsonString);
+    const json = JSON.parse(value);
+
     return json;
   } catch (e) {
-    return jsonString;
+    return value;
   }
 };
 var generateFormData = (formData, preserveStringified = false) => {
   const outputObject = {};
   for (const [key, value] of formData.entries()) {
-    const data = preserveStringified ? value : tryParseJSON(value.toString());
+    const data = preserveStringified ? value : tryParseJSON(value);
     const keyParts = key.split(".");
     let currentObject = outputObject;
     for (let i = 0; i < keyParts.length - 1; i++) {
@@ -76,7 +80,7 @@ var createFormData = (data, stringifyAll = true) => {
       }
       continue;
     }
-    if (value instanceof Array && value.length > 0 && (value[0] instanceof File || value[0] instanceof Blob)) {
+    if (value instanceof Array && value.length > 0 && value.every((item) => item instanceof File || item instanceof Blob)) {
       for (let i = 0; i < value.length; i++) {
         formData.append(key, value[i]);
       }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant