Last active
October 27, 2016 05:42
-
-
Save AbeIka/378a6fbec280210fbc039bc266ff3719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import cgi | |
import cgitb; cgitb.enable() | |
import os, sys | |
import sssp_name | |
import subprocess | |
import boto3 | |
import StringIO | |
print "Content-Type: text/html" | |
TMP_DIR = "../tmp" | |
def save_uploaded_file (upload_dir): | |
form = cgi.FieldStorage() | |
fileitem = form["file"] | |
fout = file (os.path.join(upload_dir, os.path.basename(fileitem.filename)), 'wb') | |
while 1: | |
chunk = fileitem.file.read(100000) | |
if not chunk: break | |
fout.write (chunk) | |
fout.close() | |
return(fileitem.filename) | |
# File Save (TMP_DIR) | |
file_name=save_uploaded_file(TMP_DIR) | |
file_pname=os.path.join(TMP_DIR, os.path.basename(file_name)) | |
file_names=[file_pname] | |
# SAVDI | |
resp = sssp_name.virus_check(file_names) | |
if resp >= 2: | |
print "Virus found" | |
elif resp == 1: | |
print "Unable to check file" | |
else: | |
s3 = boto3.resource('s3') | |
s3.meta.client.upload_file(file_pname, 's3-bucketname', file_name) | |
os.remove(file_pname) | |
print "Upload ok" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment