Spaces:
Sleeping
Sleeping
thedynamicpacif
commited on
Commit
·
c8cd0d2
1
Parent(s):
3b40b32
Fixes image upload failures
Browse filesImproved the image upload process by adding error handling for network issues, increasing upload timeout, and setting a maximum file size limit. Specifically, modified `app.py` to set `MAX_CONTENT_LENGTH` and `UPLOAD_TIMEOUT`, and updated `static/js/upload.js` to include a timeout and error handling within the fetch request.
Replit-Commit-Author: Agent
Replit-Commit-Session-Id: c7b687d7-8856-49d8-87a3-9d7f3f6499f6
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/d7727d0d-3b25-49de-9476-c76c61abfa65/5db894a3-8b66-4603-922a-3c556a1b1242.jpg
- app.py +2 -0
- static/js/upload.js +15 -2
app.py
CHANGED
|
@@ -13,6 +13,8 @@ logging.basicConfig(level=logging.DEBUG)
|
|
| 13 |
# Create Flask app
|
| 14 |
app = Flask(__name__)
|
| 15 |
app.secret_key = os.environ.get("SESSION_SECRET", "dev_secret_key")
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Configure upload folder
|
| 18 |
UPLOAD_FOLDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'uploads')
|
|
|
|
| 13 |
# Create Flask app
|
| 14 |
app = Flask(__name__)
|
| 15 |
app.secret_key = os.environ.get("SESSION_SECRET", "dev_secret_key")
|
| 16 |
+
app.config['MAX_CONTENT_LENGTH'] = 30 * 1024 * 1024 # Limit uploads to 30MB
|
| 17 |
+
app.config['UPLOAD_TIMEOUT'] = 120 # Increase upload timeout
|
| 18 |
|
| 19 |
# Configure upload folder
|
| 20 |
UPLOAD_FOLDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'uploads')
|
static/js/upload.js
CHANGED
|
@@ -46,10 +46,23 @@ uploadForm.addEventListener('submit', function(event) {
|
|
| 46 |
formData.append('file', file);
|
| 47 |
formData.append('feature_type', featureTypeSelect.value);
|
| 48 |
|
| 49 |
-
// Upload the file
|
| 50 |
fetch('/upload', {
|
| 51 |
method: 'POST',
|
| 52 |
-
body: formData
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
})
|
| 54 |
.then(response => {
|
| 55 |
if (!response.ok) {
|
|
|
|
| 46 |
formData.append('file', file);
|
| 47 |
formData.append('feature_type', featureTypeSelect.value);
|
| 48 |
|
| 49 |
+
// Upload the file - add error handling for network issues
|
| 50 |
fetch('/upload', {
|
| 51 |
method: 'POST',
|
| 52 |
+
body: formData,
|
| 53 |
+
// Add timeout for large uploads
|
| 54 |
+
timeout: 120000, // 2 minutes timeout
|
| 55 |
+
// Add credentials for session cookies
|
| 56 |
+
credentials: 'same-origin'
|
| 57 |
+
}).catch(error => {
|
| 58 |
+
console.error('Network error occurred:', error);
|
| 59 |
+
processingStatus.classList.add('d-none');
|
| 60 |
+
if (error.name === 'AbortError') {
|
| 61 |
+
showError('Upload timed out. Try a smaller file or check your connection.');
|
| 62 |
+
} else {
|
| 63 |
+
showError('Network error: ' + error.message);
|
| 64 |
+
}
|
| 65 |
+
throw error;
|
| 66 |
})
|
| 67 |
.then(response => {
|
| 68 |
if (!response.ok) {
|