summaryrefslogtreecommitdiffstats
path: root/grandlyon_cartads_cs/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'grandlyon_cartads_cs/models.py')
-rw-r--r--grandlyon_cartads_cs/models.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/grandlyon_cartads_cs/models.py b/grandlyon_cartads_cs/models.py
index f513065..a029318 100644
--- a/grandlyon_cartads_cs/models.py
+++ b/grandlyon_cartads_cs/models.py
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import base64
+import os
+
from django.core.cache import cache
from django.db import models
from django.utils.translation import ugettext_lazy as _
@@ -40,6 +43,12 @@ class GLCartaDSCS(AbstractCartaDSCS):
token_url = models.URLField(_('Token URL'), max_length=256)
token_authorization = models.CharField(_('Token Authorization'), max_length=128)
+ sendfile_ws_url = models.URLField(
+ _('Sendfile Webservice URL'),
+ max_length=256, blank=True)
+ sendfile_ws_dirname = models.CharField(
+ _('Sendfile Webservice Directory Name'),
+ max_length=256, blank=True)
verify_cert = models.BooleanField(default=True,
verbose_name=_('Check HTTPS Certificate validity'))
@@ -68,3 +77,15 @@ class GLCartaDSCS(AbstractCartaDSCS):
cache.set(cache_key, token, timeout)
self.logger.debug('new token: %s (timeout %ss)', token, timeout)
return token
+
+ def upload_zip(self, zip_filename):
+ b64_zip = base64.b64encode(open(zip_filename).read())
+ chunk_size = 16777216 # 16MB
+ for n in range(0, len(b64_zip), chunk_size):
+ resp = self.requests.post(self.sendfile_ws_url,
+ data={
+ 'fileName': self.sendfile_ws_dirname + os.path.basename(zip_filename),
+ 'b64_fileContent': b64_zip[n:n+chunk_size],
+ }
+ )
+ resp.raise_for_status()