Converting docx/pdf file in s3 to txt file and storing in s3 using python + boto3
<p>My situation is that I have docx/pdf files stored in S3. I need to convert these file into txt file and then store the converted file in S3. I am using docx2txt library (docx2txt 0.5: <a href="https://pypi.python.org/pypi/docx2txt/" rel="nofollow">https://pypi.python.org/pypi/docx2txt/</a>). Below is my code and the error:</p>

<pre><code>import boto3
import docx2txt
s3 = boto3.resource('s3')
bucket = s3.Bucket('client-shared-file')
obj = s3.Object(bucket.name, 'key name');
text = docx2txt.process(obj.get()['Body']) //I also tried .read() but still not work
print(text)
</code></pre>

<p>Error:</p>

<pre><code>Traceback (most recent call last):
  File ".../PycharmProjects/untitled/test.py", line 6, in &lt;module&gt;
    text = docx2txt.process(obj.get()['Body'])
  File "...\Anaconda3\lib\site-packages\docx2txt\docx2txt.py", line 76, in process
    zipf = zipfile.ZipFile(docx)
  File "...\Anaconda3\lib\zipfile.py", line 1026, in __init__
    self._RealGetContents()
  File "...\Anaconda3\lib\zipfile.py", line 1089, in _RealGetContents
    endrec = _EndRecData(fp)
  File "...\Anaconda3\lib\zipfile.py", line 241, in _EndRecData
    fpin.seek(0, 2)
AttributeError: 'StreamingBody' object has no attribute 'seek'
</code></pre>

<p>This is the Object: </p>

<pre><code>{
    'ResponseMetadata': {
        'RequestId': 'RequestId', 
        'HostId': 'HostId', 
        'HTTPStatusCode': 200
        }, 
    'AcceptRanges': 'bytes', 
    'Metadata': {}, 
    'ContentType': 'application/msword', 
    'ContentLength': 66235, 
    'Body': &lt;botocore.response.StreamingBody object at 0x00000219C885FF28&gt;, 
    'ETag': '"ETag"', 
    'LastModified': 'LastModified'
}
</code></pre>

<p>It seems like the boto3 StreamingBody could not be used as docx file in docx2txt function. Is there anyway to convert these files on s3 or what did I do wrong in the process? Help is really appreciated. Thanks in advance.</p>