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

[WIP] Use Ajax to send files in receive mode to workaround browser bug with large files #901

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions share/static/js/receive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var form = document.getElementById('send');
var fileSelect = document.getElementById('file-select');
var uploadButton = document.getElementById('send-button');

form.onsubmit = function(event) {
event.preventDefault();

// Update button text.
uploadButton.innerHTML = 'Uploading...';

// Get the selected files from the input.
var files = fileSelect.files;

// Create a new FormData object.
var formData = new FormData();

// Loop through each of the selected files.
for (var i = 0; i < files.length; i++) {
var file = files[i];

// Add the file to the request.
formData.append('file[]', file, file.name);
}

// Set up the request.
var xhr = new XMLHttpRequest();

// Open the connection.
xhr.open('POST', window.location.pathname + '/upload', true);

xhr.onload = function() {
if (xhr.status == 200) {
uploadButton.innerHTML = 'Send Files';
}
}

// Send the Data.
xhr.send(formData);
}

7 changes: 4 additions & 3 deletions share/templates/receive.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ <h1>OnionShare</h1>
<p><img class="logo" src="/static/img/logo_large.png" title="OnionShare"></p>
<p class="upload-header">Send Files</p>
<p class="upload-description">Select the files you want to send, then click "Send Files"...</p>
<form method="post" enctype="multipart/form-data" action="{{ upload_action }}">
<p><input type="file" name="file[]" multiple /></p>
<p><input type="submit" class="button" value="Send Files" /></p>
<form id="send" method="post" enctype="multipart/form-data" action="{{ upload_action }}">
<p><input type="file" id="file-select" name="file[]" multiple /></p>
<p><button type="submit" id="send-button" class="button">Send Files</button></p>
<div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
Expand All @@ -34,5 +34,6 @@ <h1>OnionShare</h1>
</form>
</div>
</div>
<script src="/static/js/receive.js"></script>
</body>
</html>