Skip to content

Commit faa4859

Browse files
committed
"code till receiving data on flask server"
1 parent f7d6bed commit faa4859

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
android:label="@string/app_name"
1414
android:supportsRtl="true"
1515
android:theme="@style/AppTheme"
16-
android:requestLegacyExternalStorage="true">
16+
android:requestLegacyExternalStorage="true"
17+
android:usesCleartextTraffic="true">
1718

1819
<activity
1920
android:name=".MainActivity"

app/src/main/java/com/googleresearch/capturesync/MainActivity.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,26 @@ private void handleWebSocketMsg(@NotNull WsMessageContext wsMessageContext){
388388

389389
case "UPLOAD" :
390390
Log.i(TAG,"handling the message in DOWNLOAD:" + infoParts[1] );
391+
try {
392+
File sdcard = Environment.getExternalStorageDirectory();
393+
String filePath = sdcard.getAbsolutePath()+ "/RecSync/VID/";
394+
File path = new File(filePath);
395+
File list[] = path.listFiles();
396+
String filename;
397+
for(int i=0; i< list.length; i++){
398+
filename = list[i].getName();
399+
if(filename.startsWith(infoParts[2])){
400+
String[] fileList = {filePath + filename};
401+
new RemoteFileUpload().execute(fileList);
402+
}
403+
}
404+
}
405+
catch(Exception e){
406+
Log.i(TAG,"In exception block");
407+
e.printStackTrace();
408+
}
409+
410+
391411
break;
392412

393413

fileserver/file_server.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
from flask import Flask, json, request, jsonify
33
import os
44
import urllib.request
5+
import base64
56
from werkzeug.utils import secure_filename
7+
import multipart as mp
68

9+
try:
10+
from io import BytesIO
11+
except ImportError:
12+
from StringIO import StringIO as BytesIO
713
app = Flask(__name__)
814

915
app.secret_key = "recSync-fileserver"
1016

1117
UPLOAD_FOLDER = 'static/uploads'
1218
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
1319

14-
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
20+
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'mov', 'mp4'])
1521

1622
def allowed_file(filename):
1723
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@@ -23,37 +29,25 @@ def main():
2329
@app.route('/upload', methods=['POST'])
2430
def upload_file():
2531
# check if the post request has the file part
26-
if 'files[]' not in request.files:
32+
data = request.get_data()
33+
import pdb;pdb.set_trace()
34+
dd = b''.join(data.split(b'\r')[3:6])[2:]
35+
#dd = data.split(b'\r')[5]
36+
with open('binary.mp4', 'wb') as wfile:
37+
wfile.write(dd.decode())
38+
39+
if 'name' not in request.files:
40+
print("request inside files not found")
2741
resp = jsonify({'message' : 'No file part in the request'})
42+
print(resp.data)
2843
resp.status_code = 400
2944
return resp
3045

31-
files = request.files.getlist('files[]')
32-
3346
errors = {}
3447
success = False
35-
36-
for file in files:
37-
if file and allowed_file(file.filename):
38-
filename = secure_filename(file.filename)
39-
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
40-
success = True
41-
else:
42-
errors[file.filename] = 'File type is not allowed'
43-
44-
if success and errors:
45-
errors['message'] = 'File(s) successfully uploaded'
46-
resp = jsonify(errors)
47-
resp.status_code = 500
48-
return resp
49-
if success:
50-
resp = jsonify({'message' : 'Files successfully uploaded'})
51-
resp.status_code = 201
52-
return resp
53-
else:
54-
resp = jsonify(errors)
55-
resp.status_code = 500
56-
return resp
48+
resp = jsonify({"message" : "git files"})
49+
resp.status_code = 200
50+
return resp
5751

5852
if __name__ == '__main__':
59-
app.run(debug=True)
53+
app.run(host='0.0.0.0', port=5000,debug=True)

remote_control/remote_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def statusBtn(self):
3434
self.label.setText(message)
3535
def downloadBtn(self):
3636
endpoint = self.api_input.toPlainText()
37-
self.ws.send("UPLOAD@@"+endpoint+"@@testsession")
37+
self.ws.send("UPLOAD@@"+endpoint+"@@Test_UPLOAD")
3838

3939
def setupUi(self, MainWindow):
4040
self.ws = websocket.WebSocket()

0 commit comments

Comments
 (0)