add support for custom zip upload webservice (#32141)
This commit is contained in:
parent
93f2b20a2a
commit
c281c34b7d
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.12 on 2019-04-18 09:18
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('grandlyon_cartads_cs', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='glcartadscs',
|
||||
name='sendfile_ws_dirname',
|
||||
field=models.CharField(blank=True, max_length=256, verbose_name='Sendfile Webservice Directory Name'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='glcartadscs',
|
||||
name='sendfile_ws_url',
|
||||
field=models.URLField(blank=True, max_length=256, verbose_name='Sendfile Webservice URL'),
|
||||
),
|
||||
]
|
|
@ -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()
|
||||
|
|
Reference in New Issue